Opened 13 months ago

Closed 4 weeks ago

#1328 closed defect (invalid)

(import (only ...)) strange behaviour

Reported by: caolan Owned by:
Priority: major Milestone: someday
Component: unknown Version: 4.11.0
Keywords: Cc:
Estimated difficulty:

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.

Change History (1)

comment:1 Changed 4 weeks ago by sjamaan

  • Resolution set to invalid
  • Status changed from new to closed

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.

Note: See TracTickets for help on using tickets.