문제

I wrote the following example, in an attempt to experiment with R7RS libraries in Chibi Scheme 0.5.3:

(define-library (example hello)
    (export hello-world)
    (import (scheme base))
    (begin
      (define (hello-world) "hello, world"))) 

(import (scheme write)
        (example hello))
(write (hello-world))

Unfortunately when executed, it generates an error about an undefined variable:

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

I must be making a simple mistake but don't see it. Any ideas?

도움이 되었습니까?

해결책

Turns out it was a simple mistake - according to the Module System section of the user guide, the file name must match the module name:

The definition of the module (foo bar baz) is searched for in the file "foo/bar/baz.sld".

So in this case the above library definition needs to be added to example/hello.sld and the import section needs to be extracted into a new .scm file (or input on the REPL, etc).

Anyway, a trivial solution but maybe it will be of help to someone else out there...

다른 팁

In general, R7RS doesn't define how to make libraries visible to a Scheme system, and the meaning of code that mixes define-library with other Scheme forms isn't defined.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top