Re: Module Loading in Lisp - Newbie question


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:

var = 20

import a
a.var = 40

import a
import b
print a.var

What will 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 -- despite its name, though, I
don't mean to imply you're an idiot. (Stupid tutorial name,
that.) :)

~ Matthias


Relevant Pages

  • Re: Finding installed package files
    ... for making installation information more easily accessible? ... >> somewhere where more information about the key parts of the package ... >> As an example I installed the latest Python on Fedora 3. ... what one would expect is a form of help documentation much more integrated ...
  • Re: Python syntax in Lisp and Scheme
    ... dislike blatantly arguing with people over language choice. ... I think that if you can get over S-exps then Scheme and Common Lisp ... feel very like python. ...
  • stdeb - Python to Debian source package conversion utility
    ... I would like to announce the initial public release of stdeb, ... stdeb - Python to Debian source package conversion utility ... produces a Debian source package of a Python package. ...
  • Re: pythons setuptools (eggs) vs rubys gems survey/discussion
    ... discussion beyond language-specific package and dependency management. ... simultaneous widespread use is a clear python weakness and can make ... they resemble classic distutils package installations. ...
  • Re: PyWart: "Pythons import statement and the history of external dependencies"
    ... Python for "bad design" when you couldn't even be bothered to use the ... the ricklib package, and you're using Python 2, and you don't have ... top of your module, and poof, implicit relative imports don't happen. ... sys.path in one file in order to import the coconut module: ...