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

Function names and function objects



I had a feeling this would finally come up when we had to vote on it.
Apparently several people missed my message on this subject about a
month ago.  I will resend it for the benefit of those people.  Let me
also restate some important points:

Function names (lambda expressions and symbols) are not the same as
function objects (lexical closures and compiled code objects).  The
special forms FUNCTION and QUOTE are only related by historical
confusion.  Function evaluation (the process which produces a function
object from a function name) is entirely unrelated to function
application.  If the semantics of a function object depend on the
environment in which a name is evaluated to produce it, the function
name and the function object cannot be the same.  It was an
implementation convenience in dynamically-scoped Lisps, where the
semantics of the function object depended only on the environment at
function application time, to make function names and function objects
the same.  In a lexically-scoped Lisp, a single function name may be
evaluated in different places or at different times to produce different
function objects.

This means that symbols as well as lambda expressions would be
disallowed as function objects.  It may be a bitter pill to swallow, but
it would be extremely unfortunate if this confusion were to be continued
in Common Lisp.  If it is too hard to convert programs immediately,
perhaps we can have a "phase-out" period, where symbols applied as
functions will be evaluated via SYMBOL-FUNCTION, and lambda expressions
when applied will be closed in the null lexical environment (certainly
NOT in the enviroment of the call!).  Implementations would warn that
this usage is archaic, and at some agreed-upon time in the future the
warning would change into an error.

This is not simply a matter of being dogmatic.  We would laugh at the
suggestion that taking the CDR of a symbol, if it happened to be a
special variable bound to a list, would return the CDR of the list it
was bound to.  Yet this is exactly analogous to using the dynamic
function value of a symbol if it happens to get applied.  We should not
confuse function evaluation with function application just because they
most commonly happen at about the same time in ordinary function calls.

-- Eric