附加字符串在IronScheme现有的文本文件 [英] Append string to existing textfile in IronScheme

查看:155
本文介绍了附加字符串在IronScheme现有的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力构建使用IronScheme日志文件,我们已经写了一个code。使用球拍它。它工作在球拍很好,但IronScheme抛出一个错误。这是我们到目前为止有:

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:

(define write-to-log
(lambda(whatToWrite)
(with-output-to-file "robot-log.txt"
(lambda () (printf (string-append whatToWrite "\r\n" ))) #:exists 'append)))

请参阅我们如何使用与输出到文件中使用时,存在可选参数。我们不知道如何使IronScheme此可选参数的工作。有没有得到这个任何方式工作,或替代方法?

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?

请注意,我们想将一个字符串追加到现有的.txt文件。如果我们不使用可选参数,则会引发错误说,该文件已经存在。

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.

推荐答案

IronScheme支持R6RS:)

IronScheme supports R6RS :)

文件选项并非适用于与输出到文件,所以你需要使用打开文件的输出端口

file-options are not available on with-output-to-file, so you need to use open-file-output-port.

示例(不正确):

(let ((p (open-file-output-port "robot-log.txt" (file-options no-create))))
  (fprintf p "~a\r\n" whatToWrite)
  (close-port p))

更新:

将上面的不可以的工作。看来你可能已经发现了IronScheme的错误。它不是从虽然明确R6RS什么文件选项应该表现得像追加,如果有的话在所有。我将调查多一些并提供反馈。

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.

更新2:

我曾与R6RS的编辑之一,而且它不会出现有移植的方式指定附加模式。当然,我们,在.net中,此可用,因此我将通过添加另一个文件选项追加为解决该问题。我也想加入一些重载为'简单IO的程序来处理这个作为使用上述code是相当繁琐的。感谢察觉的问题!

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!

更新3:

我已经解决了这个问题。从TFS转速114008,追加已被添加到文件选项。此外,与输出到文件呼叫与输出文件开放式输出文件有一个附加的可选参数,表示附加模式。你可以从 http://build.ironscheme.net/ 最新版本。

I have addressed the issue. From TFS rev 114008, append has been added to file-options. Also, with-output-to-file, call-with-output-file and 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)

这篇关于附加字符串在IronScheme现有的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆