[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making a lambda-expr more like a fn
- To: info-mcl
- Subject: Re: Making a lambda-expr more like a fn
- From: espen@coli.uni-sb.de (Espen J. Vestre)
- Date: 17 Nov 92 13:38:08 GMT
- Newsgroups: comp.lang.lisp.mcl
- Organization: Computerlinguistik, Universitaet des Saarlandes
- References: <9211161528.AA16443@cambridge.apple.com>
- Sender: news@coli.uni-sb.de (Usenet news system)
In article <9211161528.AA16443@cambridge.apple.com> Bill St. Clair,
bill@cambridge.apple.com writes:
>3) write (funcall 'coerce x 'function) instead of (coerce x 'function)
> This will be slightly slower than option 2, but I doubt you'll notice.
something which as far as I can see has been left unclear in this
discussion, is the fact that the function returned by (funcall 'coerce x
'function) is _different_ from the one that x itself denotes. For
instance,
(list
(progn
(setq x 'initial-x)
(list
(let ((x 'old-value))
((lambda ()(setq x 'new-value)))
x)
x))
(progn
(setq x 'initial-x)
(list
(let ((x 'old-value))
(funcall (funcall 'coerce '(lambda ()(setq x 'new-value))
'function))
x)
x)))
evaluates to ((new-value initial-x) (old-value new-value)).
I.e., the effect of (coerce x 'function) is _not_ a function which does
exactly what x would have done in the same lexical position, but rather
the function given by (eval `(function ,x)), i.e. the function x denotes
in a null lexical environment.
A much better idea, I think, is to consequently enclose
lambda-expressions in #' where they are defined, and to include (declare
(special...)) in the lambda expression for those variables which are to
have dynamic scope.
--------------------------------------------------------------
Espen J. Vestre, espen@coli.uni-sb.de
Universitaet des Saarlandes,
Computerlinguistik, Gebaeude 17.2
Im Stadtwald, tel. +49 (681) 302 4501
D-6600 SAARBRUECKEN, Germany fax. +49 (681) 302 4351
--------------------------------------------------------------