Create a library accessible from csi

Let's say I have a library foo in foo.scm like so:

(module foo (bar)
  (import scheme)

  (define (bar arg)
    (+ 5 arg)))

And I have a program program.scm:

(use foo)

(display (bar 2))

Now, I compile foo and generate the import library using csc -J -library foo.scm, and then compile program with csc program.scm. Running program displays "7", as expected and everything is dandy. However, I want to load program interactively in the interpreter (csi), but now for some reason each call to a function in foo has to be prefixed with foo#, i.e. in the interpreter (foo#bar 2) works, but (bar 2) doesn't even though it works when used in a source file.

Why is this? Not only is this slightly annoying, I'm also afraid that I may have a misunderstanding of how the module system works in Chicken, so any clarification would be much appreciated.

Upvotes: 1

Views: 84

Answers (1)

sjamaan
sjamaan

Reputation: 2292

I'm not sure what you mean by "load the program into the interpreter", but usually (use foo) should load and import the library, so performing (load "program.scm") should do just that, and all the things exported by foo should be available at toplevel.

It sounds like you somehow ended up with a situation where the library has been loaded into the running system, but hasn't been imported for use at toplevel. Just typing (use foo) (or even (import foo)) at the REPL should fix this problem.

CHICKEN's module system has been designed to allow for separate compilation, which makes cross-compilation possible. To make this work, the import library and actual implementation have been separated, but this complicates things a little, as you've discovered. This is needed because the import library may define macros that are needed at compile-time, so it needs to run on the cross-compiling host, whereas the library itself will need to be available in the cross-compilation target's architecture. We're discussing on how to simplify this for CHICKEN 5, as this is something that confuses many beginners (and sometimes advanced users, too).

Upvotes: 1

Related Questions