Io R5RS方案输入输出:如何向输出文件写入/追加文本?

Io R5RS方案输入输出:如何向输出文件写入/追加文本?,io,scheme,read-write,r5rs,meep,Io,Scheme,Read Write,R5rs,Meep,在兼容R5RS的Scheme版本中,将文本输出到文件的简单方法是什么? 我使用麻省理工学院的MEEP(它使用Scheme编写脚本),我想将文本输出到文件中。我在Stackoverflow上找到了以下其他答案: 但是,它们并不是我想要的。查理·马丁(Charlie Martin)、本·鲁杰斯(Ben Rudgers)和维杰·马修(Vijay Mathew)的答案非常有用,但我想给出一个对像我这样的新策划人来说简单易懂的答案:) 而且,有关整个“\r\n”事件的任何悬而未决的问题,请参阅以下答

在兼容R5RS的Scheme版本中,将文本输出到文件的简单方法是什么? 我使用麻省理工学院的MEEP(它使用Scheme编写脚本),我想将文本输出到文件中。我在Stackoverflow上找到了以下其他答案:


但是,它们并不是我想要的。

查理·马丁(Charlie Martin)、本·鲁杰斯(Ben Rudgers)和维杰·马修(Vijay Mathew)的答案非常有用,但我想给出一个对像我这样的新策划人来说简单易懂的答案:)

而且,有关整个“\r\n”事件的任何悬而未决的问题,请参阅以下答案:


干杯

你测试过这个吗?我相信你的展示声明中缺少了一个参数。只要我们在这里。为什么不定义包含换行符的文本呢?谢谢大家对括号的提示。我在另一台机器上写这段代码,所以我错过了。关于“\n”,当然可以输入文本字符串,但是如果您试图附加函数的输出,这会使它更清晰。
; This call opens a file in the append mode (it will create a file if it doesn't exist)
(define my-file (open-file "my-file-name.txt" "a"))

; You save text to a variable
(define my-text-var1 "This is some text I want in a file")
(define my-text-var2 "This is some more text I want in a file")

; You can output these variables or just text to the file above specified
; You use string-append to tie that text and a new line character together.
(display (string-append my-text-var1 "\r\n" my-file))
(display (string-append my-text-var2 "\r\n" my-file))
(display (string-append "This is some other text I want in the file" "\r\n" my-file))

; Be sure to close the file, or your file will not be updated.
(close-output-port my-file)