1

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

I am trying to log some info to the file for debugging, and transcript-on doesn't seem to be implemented...

Right now I am scraping along by reading the entire file (one character at a time!), concatenating that into a string, concatenating my text to the end of that, then writing it all out to the file again.

There must be a better way!

starblue
  • 55,348
  • 14
  • 97
  • 151

2 Answers2

3

It's going to be something like

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

You want to look up the file-options function.

Update

Here's the guile version:

(open-file "myfilename.dat" "a")
Community
  • 1
  • 1
Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • hmm... that gets me to the right part of the docs at least (: GIMP doesn't recognize file-options, alas... –  Feb 13 '09 at 05:55
  • Try the open-file flag. Unfortunately, it's very hard to axiomatize this stuff, so Scheme doesn't specify it at all. – Charlie Martin Feb 13 '09 at 16:07
0

Just had the same exact problem in GIMP and decided to use open-input-output-file. My solution is something like this:

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

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

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

LuisR
  • 99
  • 1
  • 3