We are trying to construct a log file using IronScheme, and we have written a code for it using racket. It works fine in racket, but IronScheme throws an error. This is what we have so far:
(lambda () (printf (string-append whatToWrite "\r\n" ))) #:exists 'append)))
See how we use the "exists" optional parameter when using with-output-to-file. We are not sure how to make this optional parameter work with IronScheme. Are there any ways of getting this to work, or alternative methods?
Please note that we would like to append a string to an existing .txt file. If we don't use the optional argument, an error is thrown saying that the file already exists.
Best How To :
IronScheme supports R6RS :)
file-options are not available on
with-output-to-file, so you need to use
Example (not correct):
(let ((p (open-file-output-port "robot-log.txt" (file-options no-create))))
(fprintf p "~a\r\n" whatToWrite)
The above will not work. It seems you might have found a bug in IronScheme. It is not clear though from R6RS what
file-options should behave like append, if any at all. I will investigate some more and provide feedback.
I have spoken to one of the editors of R6RS, and it does not appear to have a portable way to specify 'append mode'. We, of course have this available in .NET, so I will fix the issue by adding another
file-options for appending. I will also think about adding some overloads for the 'simple io' procedures to deal with this as using the above code is rather tedious. Thanks for spotting the issue!
I have addressed the issue. From TFS rev 114008,
append has been added to
open-output-file has an additional optional parameter to indicate 'append-mode'. You can get the latest build from http://build.ironscheme.net/.
(with-output-to-file "test.txt" (lambda () (displayln "world")) #t)