Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chibi Scheme - Simple define-library example not working

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?

like image 952
Justin Ethier Avatar asked May 03 '12 21:05

Justin Ethier


2 Answers

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

like image 157
Justin Ethier Avatar answered Nov 10 '22 05:11

Justin Ethier


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.

like image 22
John Cowan Avatar answered Nov 10 '22 07:11

John Cowan