Subject: Re: seperation of function namespace
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 18 May 2006 23:51:58 -0500
Newsgroups: comp.lang.lisp
Message-ID: <Me2dnY0qeIlz0_DZ4p2dnA@speakeasy.net>
Kaz Kylheku <kkylheku@gmail.com> wrote:
+---------------
| The symbol-function slot of a symbol isn't even necessarily the active
| function binding in a given scope, since it could be shadowed by a
| lexical binding. In that case, whatever you put in there makes no
| difference anyway.
...
| What happens in (SYMBOL-FUNCTION 'FOO) is completely irrelevant; it's
| up to the guts of that function. A Lisp-2 dialect doesn't even have to
| have that function.
+---------------

Well, a *Common Lisp* implementation has to have the function
SYMBOL-FUNCTION, but it certainly doesn't have to work by accessing
a "slot" in the SYMBOL object itself.  ;-}

For a prime example, if you look under CMUCL's covers [and by this I
mean examine internal binary representations], you will find that the
symbol objects do not even *HAVE* a symbol-function slot!! Really.[1]

Instead, that information is kept in an implementation-internal
"INFO" database, and all of the "SYMBOL-xxx" and "Fxxx" functions
that in other implementations might access the symbol-function
slot access that INFO database instead. Distilling out a bunch of
extra layers and auxiliary functions and error checks [and ignoring
the "function wrappers" facility!], to a first approximation you
have this sort of thing:

    (defun symbol-function (name)
      (fdefn-function			  ; extract function from FDEFN
        (info function definition name))) ; INFO a macro, args 1,2 not eval.

    (defun fdefinition (name)
      (fdefn-function
        (info function definition name)))

    (defun fboundp (name)
      (let ((fdefn (info function definition name)))
	(and fdefn (fdefn-function fdefn) t)))

E.g.:

    > (info function definition '+)

    #<FDEFINITION object for +>
    T
    > (lisp::fdefn-function *)

    #<Function + {1016A5F1}>
    > 

[Obviously, nearly all of those INFO accesses get optimized away
in compiled code...]

So in this case the implementation really *does* make a big deal
out of CL being a Lisp2.


-Rob

[1] Yes, I confess that I found this odd. But it's true. Here's the
    C structure for a CMUCL symbol. Look, Ma! No "function" slot!

	struct symbol {
	    lispobj header;
	    lispobj value;
	    lispobj hash;
	    lispobj plist;
	    lispobj name;
	    lispobj package;
	};

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607