[pro] Lisp 2's and function values.

Alessio Stalla alessiostalla at gmail.com
Wed May 25 15:15:34 UTC 2011


On Wed, May 25, 2011 at 4:45 PM, Matthew Swank
<akopa.gmane.poster at gmail.com> wrote:
> Pascal Costanza <pc at ...> writes:
>
>>
>>
>> On 25 May 2011, at 04:51, Matthew D. Swank wrote:
>
>> > However, consider the following:
>> >
>> > ((returns-a-function) arg arg ...)
>> >
>> > Would it be reasonable to allow this as a legal form as well?
>> >
>> > I'm not arguing Common Lisp should work this way, but I seems to make
>> > sense in the context of a Kernel like evaluator.
>>
>> _If_ (returns-a-function) indeed returns a function, then this could be ok.
>> But what if it doesn't return a function? What if it is a macro that
>> returns just a symbol? Do you want to risk that ((return-something)
>> ...) has a different meaning than (funcall (return-something) ...)?
>> This is  potentially confusing and could lead to code that is
>> hard to debug...
>>
>
> Yes you'd have to watch for symbols. The idiom would be to coerce values for use
> in the car:
>
> ((callable (returns-a-function?)) arg arg ...)
>
> or stick to using funcall.

While in principle I like such a thing, I think it doesn't play well
with Lisp-2 (or more specifically, with Common Lisp). If ((whatever)
...) is a valid expression, then one would expect (let ((foo
(whatever))) (foo ...)) to be equivalent, but it's not. And you can't
use flet/labels for the same effect. Perhaps this is an oversight in
flet: if it were a little more verbose - (flet ((x (lambda ...))) ...)
- then you could also admit a more general form (flet ((x
(returns-a-function))) ...). It would also be more symmetric with let.
Of course, in general, the compiler would only optimize the former
case, where the function is statically known. Hmm... this should go in
my "CL++" wish list :D

Alessio




More information about the pro mailing list