读取文件:语法错误(标识符后有多个表达式)
(define bootstrap-c-code
(define (from-file file-name)
(let* ((ip (open-input-file file-name))
(res (read-text-file-from-input-port ip)))
(close-input-port ip)
res))
(from-file "llvm.c"))
错误:定义:语法错误(标识符后有多个表达式)
但我看不出它有什么问题。有人可以解释/修复它吗?
(define bootstrap-c-code
(define (from-file file-name)
(let* ((ip (open-input-file file-name))
(res (read-text-file-from-input-port ip)))
(close-input-port ip)
res))
(from-file "llvm.c"))
Error : define: bad syntax (multiple expressions after identifier)
But I can't see anything wrong with it. Can someone explain / fix it please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前尚不清楚您使用上述代码的意图。如果您尝试加载文本文件并将加载的值保留在名为
bootstrap-c-code
的变量中,请尝试以下操作:当然,
from -file
定义仅在let
内部可见,如果需要在外部使用它,请在整个表达式之外define
它。如果您只需要let
中的from-file
功能,则可以通过更简单的方式获得相同的结果:另一方面,如果您的意图是创建一个名为
bootstrap-c-code
的过程,那么正确的语法是:It's not clear what you intended with the above code. If you were trying to load a text file and leave the loaded value in a variable called
bootstrap-c-code
, then try this:Of course, the
from-file
definition will only be visible inside thelet
, if you need to use it outside,define
it outside of the whole expression. If you only need the functionality offrom-file
inside thelet
, you can obtain the same result in a much simpler way:On the other hand, if what you intended was to create a procedure called
bootstrap-c-code
, then the correct syntax would be:根据R5RS,内部定义只能出现在开头一堆形式的组成,如 let、let*、lambda 等。就您的代码而言,情况并非如此,因为您在非过程定义中有一个内部定义。您可以通过将“bootstrap-c-code”绑定到过程来修复它。
According to R5RS, internal definitions can occur only at the beginning of the of a bunch of forms like let, let*, lambda etc. In the case of your code, that is not the case since you have an internal definition inside a non-procedural define. You could fix it by making `bootstrap-c-code' bind to a procedure.