Summary

(import (only ...)) strange behaviour

Metadata

Description

I noticed that I had to manually (use posix) before loading the LMDB module. But the module already does: (import (only posix create-directory delete-directory))

That has led to the following test cases:

 ;; create-directory not defined
 (import (only posix create-directory))
 (print create-directory)
 (print delete-directory)



 ;; delete-directory is imported when it shouldn't be
 (use (only posix create-directory))
 (print create-directory)
 (print delete-directory)

And this shows how I manually (use posix) beforehand to get around this issue:

 ;; module A (a.scm)
 (module a *
   (import chicken scheme)
   (import (only posix create-directory))
   (print create-directory)
   (print delete-directory))



 (use posix)
 (load "a.scm")
 (import a)

This now correctly imports _only_ the create-directory procedure. If I remove the (use posix) line, it will fail as in the first example. I can also replace (use posix) with (require-library posix) and it will work.

These examples were just run in csi - however I originally found it by using the system's installed lmdb module inside my own module compiled via csc.

Changes and comments

[2017-08-25 14:47:05 UTC] sjamaan changed status from new to closed

[2017-08-25 14:47:05 UTC] sjamaan set resolution to invalid

[2017-08-25 14:47:05 UTC] sjamaan wrote:

You need use rather than import. import doesn't load code, it only loads the so-called "import library" which registers which identifiers are exported by the module.

This is a bit of a FAQ/pitfall/caveat in CHICKEN 4. In CHICKEN 5, we've made use and import behave identically because it is rarely actually useful to only load the import library but not the code.