【问题标题】:How to write to a file in append mode -scheme R5RS?如何以附加模式写入文件-scheme R5RS?
【发布时间】:2017-04-11 13:27:49
【问题描述】:
(call-with-output-file "b.txt"
(lambda (output-port)
(display "hello, world" output-port)))

如何以附加模式打开 b.txt。这样,我的结果将附加到文本文件中。我在下面找到了一些答案。但这不是我所期望的。

Append in scheme

我想使用“call-with-output-file”。因为我发现这正常工作。有了这个带输出文件的调用,我该如何追加?

【问题讨论】:

    标签: scheme guile r5rs


    【解决方案1】:

    您提到的链接提供了正确的解决方案。在guile 中,Óscar López 的建议不起作用,因为它的call-with-output-file 没有#:exists 关键字。但是,这应该有效:

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

    您可以在ice-9/boot-9 中找到call-with-output-file 的代码。扩展它以支持追加很容易。

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 1970-01-01
      • 2011-06-14
      • 2010-10-07
      • 2011-07-28
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多