Chibi Scheme - Simple define-library example not working

1k views Asked by At

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?

2

There are 2 answers

0
Justin Ethier On BEST ANSWER

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...

0
John Cowan On

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.