[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Symbols as functions

    Date: Tue, 4 Feb 1986  13:58 EST
    From: "Scott E. Fahlman" <Fahlman@C.CS.CMU.EDU>

    We've had a bit of a debate here about whether it is legal, according
    the the current manual, to use a symbol as the Symbol-Function of
    another symbol.  (It is clear that you can pass a symbol as the function
    to Apply and that (functionp <some symbol>) is true.)  In other words,
    if I do

    (defun foo () 'barph)
    (setf (symbol-function 'foo1) 'foo)
    (setf (symbol-function 'foo2) 'foo1)

    must the system return BARPH, or is it allowed to barf?  The issue comes
    up because CommonLoops happens to do something like this and Spice Lisp
    doesn't support it at present.

    Long ago this was explicitly forbidden in Spice Lisp because it slowed
    things down and an infinitely loop of symbols calling each other was
    very hard to check for.  

I see no reason to check explicitly for it, as long as it is interruptible.  I
don't see it as different from any other infinite loop that a user might insert
into a program, accidentally or intentioanlly.  Perhaps there are
implementation reasons on the PERQ that make it difficult to make it

On the other hand, clearly anything that signals an error from your microcode
can be implemented, inefficiently, in the error-trap handler.  So you could
support this without having to support it in microcode.

			     Later Guy realized that the old trick of using
    two pointers, one moving at half speed, would detect such loops, and the
    inefficiency would only show up if you actually used such chains. SO he
    wanted to lift this restriction; I didn't, because I thought it was a
    worthless crock, and this never got changed in Spice Lisp (and
    presumably many of its progeny).  The language in the book about symbols
    being legitimate functions comes from a completely different debate, the
    one about whether it is OK to say (apply 'foo ...) instead of (apply
    #'foo ...).

    Anyway, I thought I'd see if the rest of you have some clear impression
    of what is currently required and/or what should be, before throwing
    this open to comment from the entire mailing list.

We have always allowed this in our system, and users sometimes make good use
of it to make two functions synonyms while still having redefinitions of one
propagate to the other.  (There are other ways to do that, but using a symbol
as a function definition is the only one that is both potentially efficient
and potentially legal Common Lisp.)

I can't find any evidence in the manual supporting or opposing the proposition
that (setf (symbol-function <symbol1>) <symbol2>) is legal.  The manual is
extremely coy about admitting what exactly a "function" is, I think to avoid
restricting implementations' choices of how to represent lexical closures,
compiled functions, and so forth.

My conclusion is that if we had the mechanism in place to clean up the manual
and modify the language, I would propose that the construct CommonLoops is using
be made explicitly legal.  In the meantime, the manual says nothing and it's
up to the discretion of the implementor.