[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EVAL-WHEN (really symbol-function)
Date: 8 Apr 1986 17:34-EST
1. How many implementations interpreted CLtL the way Guy intended?
In other words, How many implementations allow, for example,
(setf (symbol-function 'foo) 1.0d0). VaxLisp does not allow this.
I tried (setf (symbol-function 'foo) 'bar) in the two CLs within easy
reach. Both signal errors, and not particularly nice ones either. (I'd
expect something like "illegal value ~S for SYMBOL-FUNCTION", but I get
things like "segmentation-violation".)
3. Under interp 1. consider the following:
(defun foo () (print "hello"))
(setf (symbol-function 'bar) 'foo)
Which of the following are legal?:
(funcall 'bar) ; A
(funcall #'bar) ; B
(funcall (symbol-function 'bar)) ; C
Case C is the only one I am sure is legal. The other two depend on
the ambiguous description of function calling (pg. 58) and APPLY (pg.
Case C should be legal because it should be the same as (funcall 'foo).
Case B should also be legal because #'bar == (function bar) should be
equivalent to (symbol-function 'bar) in a context where bar refers to a
global function (i.e., when there's no lexically enclosing flet or
labels that binds bar), as it does in this case.
Case A should be illegal, but CLtL does not explicitly exclude it.
Cases B and C dereference 'bar one level in the evaluation of the
argument form; here funcall would have to do both levels (from bar to
foo and from foo to #'foo) itself. Nothing says that apply and funcall
do repeated dereferencing in this case, but that would not be an
unreasonable interpretation of pages 32 (section 2.13) and 107. Take
page 107. If 'function' is a symbol, its global functional value is
"used". Presumably, it is used as a function, in which case it is
reasonable to suppose the global value might also be a symbol and that
the same rule would be applied again.
The reason I say that case A should be illegal is that Common Lisp does
not in general repeatedly dereference symbols used as functions in this
way. Some Lisps have done so, even if you just write (f x) instead of
using FUNCALL or APPLY, but typically only in the interpreter.
I guess my point is that I think most implementors followed
interpretation 2 which prevents the kind of confusion where C is legal
but B is not; so we should clarify CLtL in that direction rather than
towards interp 1.
I don't think there is a case where C should be legal and B not. Both
should be legal if arbitrary values are allowed to be SYMBOL-FUNCTIONs;
neither should be legal otherwise. (Except in those contexts where
(FUNCTION x) does not just do (SYMBOL-FUNCTION x) -- but that does not
depend on interp 1 vs interp 2.)
Whatever interp. is finally chosen, APPLY should be clarified so that
we known exactly what can be applied (and if a symbol is applied, what
exactly can be legally the function definition).
I agree that the definition of APPLY is deficient. For example, it
seems to list explicitly all the things that might be functions and yet
it never mentions closures. Compare this list to that on page 32.
In general, my favorite pages for answering questions concerning what
things are legal as functions are pages 32 (section 2.13) and 59
(section 5.2). Page 59 is, for example, the place where the distinction
between the use of lambda-expressions and symbols as *names* for
functions and their use as function objects is most clearly made.