Summary
(import (only ...)) strange behaviour
Metadata
- Id: c7321f75af1eabb2f03aaa24b5dc2cebe16707c5
- Trac id: 1328
- Type: defect
- Reporter: caolan
- Owner:
- Cc:
- Status: closed
- Component: unknown
- Estimated difficulty:
- Resolution: invalid
- Priority: major
- Milestone: someday
- Version: 4.11.0
- Changetime: 2017-08-25 14:47:05 UTC
- Created: 2016-09-12 19:17:15 UTC
- Keywords:
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.