How to add a file to Scheme?

I am using TinyScheme (actually Script -Fu in GIMP) and cannot find a good way to open the file and add a line of text to it.

I am trying to register some information in a file for debugging, and writing to transcription does not seem to be implemented ...

Right now I am reading the entire file (one character at a time!), Combining it into a string, concatenating my text to the end, and then writing everything back to the file.

There must be a better way!

+1
source share
2 answers

It will be something like

(open-file "myfile" (file-options append)) 

You want to find the file-options function.

Update

Here 's the guile version :

 (open-file "myfilename.dat" "a") 
+2
source

GIMP just had the same problem and I decided to use open-input-output-file . My solution looks something like this:

 (let* ((out (open-input-output-file "file.txt") )) (display "hello world" out) (newline out) (close-output-port out)) 

I walked through the source of TinyScheme and checked that this function actually calls fopen with "a+" . The file is open for reading and writing. For our purposes, we just want to write, so just ignore reading.

I am writing Script -Fu to write gimp-selection-bounds values ​​to a file.

0
source

All Articles