我在显示行到文件时遇到问题,这是我尝试过的:
(define (list-to-file lst file) (display-lines-to-file lst file
#:exists 'replace
#:separator newline #"\n"))
(list-to-file myList "myfile.txt")
myList是从另一个文件读取的数据列表,在处理完我需要将列表内容(包括换行符)写入myfile.txt的数据之后
答案 0 :(得分:1)
Racket关键字参数后跟一个值#:keyword
。问题似乎是:
#:separator newline #"\n"
相反,你想:
#:separator #"\n"
我建议其他一些变化:
#:separator
的默认值已经是#"\n"
,因此请忽略它。#:mode 'text
,以便\n
在Windows上自动转换为\r\n
。结合所有这些:
(define (list->file lst file)
(display-lines-to-file lst
file
#:exists 'replace
#:mode 'text))