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: why cl packages are hard to use ?
    ... i.e. managing the mapping from identifiers to concepts. ... Unless you can guarantee that package names are globally unique there's always the possibility of wanting to combine two code bases that use the same package name. ... How would that work if I wanted to make a package and have the Common Lisp language available in that package? ... There should be a new option to import all symbols from some other package:import-package / import-package, which allows you to use all those symbols _qualified_. ...