[movitz-devel] Self-referential functions

Nyef nyef at softhome.net
Fri Mar 19 02:31:55 UTC 2004


On Thu, Mar 18, 2004 at 06:33:03PM -0600, Chris Capel wrote:
> Slightly OT, perhaps.  Reading the sources, I noticed a *lot* of things like
> 
> (defmacro defmacro
> 
> and
> 
> (defun eq (a b)
>    (eq a b))
> 
> .  How exactly does that work?  It sort of boggles my mind, really.  Is there a general explanation on the web somewhere for this technique, or could someone explain how it works in Muerte?

Well, it is a little confusing unless you know what's going on.

It's still a little confusing when you do know what's going on.

The compiler knows how to open-code the function eq, that is,
it will turn a reference to eq into the equivalent machine code
inline. But you still need the function object to exist so that
it can be funcalled, grabbed with symbol-function, function,
etc. So what the definition does is tell the compiler to make a
function object, called eq, that performs the eq operation. RPG
mentions this same thing in Patterns Of Software about the Lisp
implementation that his company wrote.

Similarly, the defmacro form you mentioned is picked up by the
-compiler- version of defmacro, which creates a macro function
for the target system (and possibly another one for the host,
since some Lisp code is written in such a way as to require it).

Is this making sense?

> Chris Capel

--Alastair Bridgewater




More information about the movitz-devel mailing list