7

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?

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
  • I don't think you need a begin in the library – Ross Larson May 04 '12 at 00:20
  • @RossLarson: I think the `begin` is part of the R7RS `define-library` form, and specifies the contents of the library. – C. K. Young May 04 '12 at 01:23
  • @ChrisJester-Young - Right, the `begin` is part of the spec and is used both in the R7RS examples and by Chibi's libraries. – Justin Ethier May 04 '12 at 01:45
  • Indeed it is, I apologize. Now that I think, my experience is with r6rs libraries, just using (library ...) and rather limited. (good thing I didn't post that as an answer, haha) – Ross Larson May 04 '12 at 01:56

2 Answers2

6

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

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
2

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.

John Cowan
  • 1,497
  • 12
  • 13