Subject: Re: Walking a list
From: (Rob Warnock)
Date: Sat, 30 Jun 2007 20:18:28 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Dan Bensen  <> wrote:
| Lisp is ALL pointers.  EVERY variable, EVERY slot in EVERY object
| or structure, is a reference to a piece of data.  In Lisp, there's
| no such thing as directly embedding one object inside another,
| as is done in C and C++.  There's no such thing as actually
| passing an object to a function.  The only thing you can contain in
| an object or pass to a function is an implicit pointer to the object. 

This is conceptually true as far as it goes, and I certainly agree
that it is is indeed the best way to present it to new users. And
in fact, for some (small) Lisp implementations [the original SIOD
Scheme comes to mind], it's the *exact* truth.

But, as with many esoterica, there is sometimes a further level
of truth, which in this instance is that *if* a particular Lisp
data type is immutable [has no components with setters] *and*
if a datum in that type can be represented in the same amount of
space as a generic Lisp reference without conflict [perhaps by
using a few bits of the "reference" as a "tag" or discriminator],
*then* the implementation is permitted to pass [copies of] the
entire object around, store them inside other [mutable] objects,
and so on. Such objects are usually called "immediates", and
many Lisps use such immediates for FIXNUMs, BASE-CHARs [though
not Unicode characters], and other small constants [e.g., an
"unbound" marker, perhaps NIL, and Schemes often use them for
#F, #T, #EOF, & #VOID (a.k.a. a zero-values marker)].

But this is merely an efficiency hack, and is not even normally
*observable* by the Lisp programmer, with one exception -- two
freshly created instances of such an "immediate" type may compare
as EQ, whereas for non-immediates EQ would fail but EQUAL [or
maybe EQL] would succeed. E.g.:

    > (let ((a (eval (read-from-string "(+ 2 3)")))
	    (b (parse-integer "000101" :radix 2)))
	(eq a b))


So in the implementation I used to run that example,
FIXNUMs are probably encoded as immediates.

| If you want to pass a new copy of the object, you have to explicitly
| create the copy, and pass a reference to it.

Again, except for immediates, where a copy of the "reference" *is*
a new copy of the "object".


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607