7

我编写了以下示例,以尝试在 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-world))

不幸的是,在执行时,它会生成有关未定义变量的错误:

$ chibi-scheme  hello.scm 
ERROR: undefined variable: hello-world

我一定是犯了一个简单的错误,但没有看到。有任何想法吗?

4

2 回答 2

6

原来这是一个简单的错误 - 根据用户指南的模块系统部分,文件名必须与模块名匹配:

在文件“foo/bar/baz.sld”中搜索模块的定义(foo bar baz)。

因此,在这种情况下,需要添加上述库定义,example/hello.sld并且需要将导入部分提取到新.scm文件中(或 REPL 上的输入等)。

无论如何,一个微不足道的解决方案,但也许它会对那里的其他人有所帮助......

于 2012-05-04T14:02:06.323 回答
2

通常,R7RS 没有定义如何使库对 Scheme 系统可见,并且没有定义将 define-library 与其他 Scheme 形式混合的代码的含义。

于 2012-11-03T18:04:43.547 回答