Scheme Chibi方案-简单定义库示例不起作用
我编写了以下示例,以尝试在Chibi Scheme 0.5.3中使用R7RS库:Scheme Chibi方案-简单定义库示例不起作用,scheme,chibi-scheme,r7rs,Scheme,Chibi Scheme,R7rs,我编写了以下示例,以尝试在Chibi Scheme 0.5.3中使用R7RS库: (define-library (example hello) (export hello-world) (import (scheme base)) (begin (define (hello-world) "hello, world"))) (import (scheme write) (example hello)) (write (hello-worl
(define-library (example hello)
(export hello-world)
(import (scheme base))
(begin
(define (hello-world) "hello, world")))
(import (scheme write)
(example hello))
(write (hello-world))
不幸的是,在执行时,它会生成一个关于未定义变量的错误:
$ chibi-scheme hello.scm
ERROR: undefined variable: hello-world
我一定是犯了个简单的错误,但我看不出来。有什么想法吗?原来这是一个简单的错误-根据《用户指南》的一节,文件名必须与模块名匹配: 在文件“foo/bar/baz.sld”中搜索模块(foo-bar-baz)的定义 因此,在这种情况下,需要将上述库定义添加到
示例/hello.sld
中,并且需要将导入部分提取到新的.scm
文件中(或在REPL上输入,等等)
无论如何,这是一个微不足道的解决方案,但可能会对其他人有所帮助…一般来说,R7RS没有定义如何使库对Scheme系统可见,而且,将define library与其他Scheme表单混合在一起的代码的含义尚未定义。我认为您不需要在library@RossLarson:我认为
开始
是R7RS定义库
表单的一部分,并指定库的内容。@ChrisJester Young-右,begin
是规范的一部分,在R7RS示例和Chibi的库中都有使用。现在我想,我的经验是使用r6rs库,只是使用(库…),而且相当有限。(幸好我没有把这当作回答,哈哈)