Discussion:
[Chicken-users] reexport - not working as expected (or I have wrong expectations)
Martin Schneeweis
2018-07-21 09:28:19 UTC
Permalink
Hi,

I am trying to reexport functions out of my own modules - but am
failing.

In my simple example I have 3 modules:

- mod-a: exports a simple function
- mod-b: does nothing except reexporting the simple function
- mod-c: imports mod-b and calls the simple function

The behaviour in chicken-4 and chicken-5 are the same - when I pack all
3 modules in the same file the whole thing works (in Chicken-4 mod-c has
to "import" mod-b rather than just "use" it).

Splitting the whole thing into 3 files does not work - I get a runtime
exception (when executing "mod-c"): "Error: unbound variable:
mod-a#test-a".

Does the modules have to be eggs to be able to reexport?

lg
Martin

The attached files are for chicken-5
k***@upyum.com
2018-07-21 12:08:58 UTC
Permalink
Post by Martin Schneeweis
Splitting the whole thing into 3 files does not work - I get a runtime
mod-a#test-a".
The one thing that is missing from your example, is that mod-a is never
loaded, this can be acheived by adding `(use mod-a)` in mod-b’s code.
Martin Schneeweis
2018-07-21 12:31:48 UTC
Permalink
Post by k***@upyum.com
Post by Martin Schneeweis
Splitting the whole thing into 3 files does not work - I get a
runtime exception (when executing "mod-c"): "Error: unbound
variable: mod-a#test-a".
The one thing that is missing from your example, is that mod-a is
never loaded, this can be acheived by adding `(use mod-a)` in mod-b’s
code.
Isn't "reexport" supposed to import? (in chicken-5 there is no
"use" (I think))

chicken-4: Yes, when I add "(use mod-a)" in mod-b then I can call
"test-a" in mod-b - but calling "test-a" in mod-c still leads to the
same runtime error

- and if I also have to include "(use mod-a)" in mod-c (or
"(import mod-c)" in chicken-5) then the purpose of "reexport" is
defeated. No?

lg
Martin
Evan Hanson
2018-07-21 22:34:04 UTC
Permalink
Hi Martin,

The reason for this behaviour is that `reexport' only manages syntax, i.e.
it imports and exports module identifiers but does not load libraries.
This is similar to the distinction between `use' and `import' in C4.
Post by Martin Schneeweis
Isn't "reexport" supposed to import? (in chicken-5 there is no
"use" (I think))
That's right, in C5 there is `import' (which corresponds to C4's `use')
and `import-syntax' (which is C4's `import').
Post by Martin Schneeweis
chicken-4: Yes, when I add "(use mod-a)" in mod-b then I can call
"test-a" in mod-b - but calling "test-a" in mod-c still leads to the
same runtime error
I believe that this will work as expected in C5.
Post by Martin Schneeweis
- and if I also have to include "(use mod-a)" in mod-c (or
"(import mod-c)" in chicken-5) then the purpose of "reexport" is
defeated. No?
I can see the case for making `reexport' load the implementation, and
potentially adding a `reexport-syntax' form to provide the current
syntax-only behaviour. I may open a feature ticket for this (or you can if
you have an account on bugs.call-cc.org), but this won't be changed in C4.

All the best,

Evan
Martin Schneeweis
2018-07-22 17:15:09 UTC
Permalink
Hi Evan,
Post by Evan Hanson
That's right, in C5 there is `import' (which corresponds to C4's
`use') and `import-syntax' (which is C4's `import').
thank you for the clarification - and thanks to kooda - if my
understanding of the differences between "import" in chicken-4 and
chicken-5 had been better your answer had helped as well.
Post by Evan Hanson
Post by Martin Schneeweis
chicken-4: Yes, when I add "(use mod-a)" in mod-b then I can call
"test-a" in mod-b - but calling "test-a" in mod-c still leads to the
same runtime error
I believe that this will work as expected in C5.
Indeed - if I change the code of mod-b (chicken-5) to

(module mod-b ()
(import scheme chicken.base chicken.module mod-a)
(reexport (only mod-a test-a)))

(mod-a is now in the import- and the reexport-form) - then "test-a" is
callable in mod-c (mod-c only imports mod-b).
Post by Evan Hanson
[...] I may open a feature ticket for this (or you can if you have
an account on bugs.call-cc.org), but this won't be changed in C4.
I don't think that's neccessary (I have an account) - import + reexport
works in chicken-5 - furthermore I am just working on a pet project
while learning (chicken) scheme (although the pet has grown quite a
bit). I am using chicken-4 (for the pet) and test with chicken-5 before
posting to avoid unnecessary noise (sorry for the fail this time
around).

Thanks again,
Martin

Loading...