简体   繁体   中英

How to write to a file in append mode -scheme R5RS?

(call-with-output-file "b.txt"
(lambda (output-port)
(display "hello, world" output-port)))

How to open the b.txt in append mode. So that, my results will be appended in the text file. I have found some answer in the following. But that's not what i expect.

Append in scheme

I want to work with "call-with-output-file". Since i find this properly working. With this call-with-output-file, how can i append?

The link you mention presents a correct solution. In guile , the suggestion by Óscar López will not work, as its call-with-output-file has no #:exists keyword. However, this should work:

(let ((output-port (open-file "my.txt" "a")))
  (display "hello, world" output-port)
  (newline output-port)
  (close output-port))

You can find the code for call-with-output-file in ice-9/boot-9 . It would be easy to extend it to support appending.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM