Jay Lee
Jay Lee

Reputation: 1912

How to use a Chicken Scheme module in a separate directory?

I have the following project structure:

.
├── main.scm
└── stream
    ├── stream.import.scm
    ├── stream.scm
    └── stream.so

stream.scm defines a module:

; stream.scm
(module stream
  (...)
  (import scheme (chicken base))
  ...)

and main.scm uses stream module:

; main.scm
(import stream)
...

I compiled stream via csc -s stream.scm -j stream. I’d like to compile the main.scm using the stream module nested in the stream directory, but I can’t find a way to do that.

I read the man page and I tried

csc main.scm -I ./stream

but it prompts a warning

Warning: the following extensions are not currently installed: stream

and the executable does not work:

Error: (require) cannot load extension: stream
...

It does work when I put main.scm in the stream directory.

What should I do to make main.scm aware of the stream module?

Upvotes: 1

Views: 312

Answers (1)

Richard Huxton
Richard Huxton

Reputation: 22943

I think you probably want to set CHICKEN_REPOSITORY_PATH for this project.

Example:

~/dev/scheme/subdir_test$ chicken-install -repository
/home/richardh/dev/chicken/lib/chicken/11

~/dev/scheme/subdir_test$ export CHICKEN_REPOSITORY_PATH="/home/richardh/dev/chicken/lib/chicken/11:/home/richardh/dev/scheme/subdir_test/sub/"
~/dev/scheme/subdir_test$ cat alpha.scm 
(import beta)

(print "Hello " (hello_name))
~/dev/scheme/subdir_test$ cat sub/beta.scm 
(module beta (hello_name)

  (import scheme)

  (define (hello_name)
    "World")
)
~/dev/scheme/subdir_test$ cd sub/
~/dev/scheme/subdir_test/sub$ csc -s beta.scm -j beta
~/dev/scheme/subdir_test/sub$ cd ..
~/dev/scheme/subdir_test$ csc alpha.scm 
~/dev/scheme/subdir_test$ ./alpha 
Hello World

If you google "chicken scheme virtualenv" you will find several examples of more sophisticated versions of this.

You might also be interested in the "chicken-belt" and "dust" eggs http://wiki.call-cc.org/chicken-projects/egg-index-5.html#tools if you want to have multiple versions of chicken itself installed.

Upvotes: 2

Related Questions