chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Advice on require, use, import, etc.


From: John Cowan
Subject: Re: [Chicken-users] Advice on require, use, import, etc.
Date: Sun, 9 Aug 2009 15:27:37 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

Sam Varner scripsit:

> I'm confused about the different ways to load extensions.  So brace
> yourself for some newbie questions and feel free to state the obvious.
> 
>      1. Should I prefer 'import' if it's available?  E.g (import srfi-4)
>         instead of (use srfi-4).

Use, which is a synonym for require-extension, both loads a file (unless
it is already loaded) and imports the names defined in any module with
the same name as that file into the current namespace (which is a no-op
if they have already been imported).  So you should use (import srfi-4)
at the top of a module that requires SRFI 4, but (use srfi-4) to load
SRFI 4 into the REPL.

>      2. Should I turn my own libraries into modules and 'import' instead
>         of 'require'?

If you do, it makes it possible for people to selectively import only
certain symbols, or to rename or prefix symbols on the fly to avoid
conflicts.  So this is a Good Thing, yes.

>      3. With any of these methods, what do I need to do to make sure
>         that the macro definitions are properly loaded?

If they are syntax-rules macros, nothing.  If they are explicit-renaming
macros and they call macros (as opposed to referring to macros) that
aren't standard Scheme or Chicken macros, then special precautions are
needed; see below.

>      4. When should 'import-for-syntax' be used?

In principle, when an explicit-renaming macro invokes (as opposed to
referring to) a name defined in another module, the module must be
imported with import-for-syntax rather than import.  Currently, this is
only necessary if the foreign name is a macro.

>      6. Are there situations where other means (load, require-extension,
>         etc.) would be the way to go?

Load just does brute-force loading of source code; it does not check if
the file has already been loaded (as require does), nor does it handle
compiled libraries specially (as load-library and require-library
do), nor does it import anything (as use and require-extension do).
Sometimes that's what you want, but not usually.

-- 
John Cowan              http://www.ccil.org/~cowan      address@hidden
"After all, would you consider a man without honor wealthy, even if his
Dinar laid end to end would reach from here to the Temple of Toplat?"
"No, I wouldn't", the beggar replied.  "Why is that?" the Master asked.
"A Dinar doesn't go very far these days, Master.        --Kehlog Albran
Besides, the Temple of Toplat is across the street."      The Profit




reply via email to

[Prev in Thread] Current Thread [Next in Thread]