Discussion:
[Chicken-users] Confused by modules
Mark Carter
2018-08-15 10:11:18 UTC
Permalink
Chicken scheme has modules, extensions, units, eggs, etc., and I'm
confused as to how it all works.


I have written a module mcutils.scm, containing:


(module
 mcutils
 (export define-syntax-rule displayln
     file->lines hello-utils until)
 (import chicken extras scheme)

...

;;; a proc calling read-line

...

)

The calling program, vas-parser.scm, contains the lines:

(include "mcutils.scm")
(use mcutils)

When I execute

csi vas-parser.scm

it all works fine.

I can compile successfully using

csc vas-parser.scm

but when I try to run vas-parser, it says that there is an unbound
variable read-line; which is in unit extras, I believe.

I think that's because the interpreter loads the extras unit
automatically, but the compiler doesn't??

But my module says to import extras, so why doesn't it work?

I must admit, I'm a bit baffled about what distinguishes
include/import/use/require-extension and when to use what under which
circumstances.
Christian Kellermann
2018-08-15 15:25:05 UTC
Permalink
Hi Mark!
Chicken scheme has modules, extensions, units, eggs, etc., and I'm confused
as to how it all works.
Oh yes, we promise that it will get easier in CHICKEN 5!
(module
 mcutils
 (export define-syntax-rule displayln
     file->lines hello-utils until)
 (import chicken extras scheme)
You need to (use extras).
Import in CHICKEN 4 only extends the namespace but does not do any
code loading. That's what use is for.

Units are traditional compiler units, better forget this term now.
Extensions are packaged modules and there may be more than one
module in an extension. That's what we call 'eggs'.
I must admit, I'm a bit baffled about what distinguishes
include/import/use/require-extension and when to use what under which
circumstances.
use and require-extension are the same. Import will expand the
namespace, which is needed for syntax modules like 'chicken' or
'scheme'. Include works like a C #include as it textually inserts
the mentioned file.

Does this help?

Kind regards,

Christian
--
May you be peaceful, may you live in safety, may you be free from
suffering, and may you live with ease.
Mark Carter
2018-08-15 16:46:42 UTC
Permalink
Post by Christian Kellermann
Does this help?
Thanks, it helps.

Loading...