Re: Module Loading in Lisp - Newbie question



Hi,

Say, I have a module called lib.lisp which has the single line.

(setf *var* 20)

I then have lib1.lisp, which has the following.

(require :lib)
(setf *var* 40)

I then have lib2.lisp which requires both lib and lib1.

(require :lib1)
(require :lib)

Then the value of *var* when finally executing lib2 is 20 and not 40.

In Python, if I have three modules, like this:

# a.py
var = 20

# b.py
import a
a.var = 40

# c.py
import a
import b
print a.var

What will c.py print?

Now, I think what confuses is you is the fact that (a) Python modules
are namespaces, whereas Lisp files aren't, and (b) you don't import
definitions in Lisp as you do in Python, but rather symbols (names).
If you want to define namespaces (packages, as they are called in
Common Lisp), you have to DEFPACKAGE them explicitely and then use IN-
PACKAGE to define stuff within them.

By the way, you don't normally use SETF to declare variables. If you
want to declare a special variable, use DEFVAR or DEFPARAMETER.
Lexical variables are introduced by LET (or LAMBDA, or DEFUN, or...).

There's a very nice introduction to the Common Lisp package system at
http://www.flownet.com/gat/packages.pdf -- despite its name, though, I
don't mean to imply you're an idiot. (Stupid tutorial name,
that.) :)

~ Matthias

.