Subject: [clisp-list] Re: Recursive macros

From: Bruce <[email-masked]>
Date: Mon, 30 Jul 2001 16:56:55 +0800

Paul Graham wrote:

> Sorry to be so long replying.  This got pushed down the
> mail stack.  I think I remember thinking that the 
> difference was due to the way compilation is done.
> In some interpreters, the macro call will be re-expanded 
> on each iteration.  See what happens when when you
> compile in both.  --pg

That's OK, and thank you. I find it out that the bad version of
recursive macro "nthb" can be interpreted and compiled happily by both
CMUCL and CLISP, only that CMUCL runs into endless loop when calling the
macro, while CLISP produces a result as the correct version.

Maybe one has to dig into the implementations to know the cause of the
difference. The important thing to know is which implementation is
taking the right action, CMUCL or CLISP.

Best!

> 
> --- Bruce <[email-masked]> wrote:
> 
>>Paul Graham wrote:
>>
>>
>>>Try using a variable instead of an integer as the first arg.
>>>
>>
>>[73]>(let ((a 2)) (nthb a '(1 2 3 4)))
>>
>> 3
>>
>>
>>No difference.
>>
>>
>>
>>>--- Bruce <[email-masked]> wrote:
>>>
>>>
>>>>Paul Graham wrote:
>>>>
>>>>
>>>>
>>>>>How are you calling the macro?  
>>>>>
>>>>>
>>>>In both CMUCL and CLISP, I call them interactively. Just now I put
>>>>them
>>>>in a file and loaded it. CMUCL kept on gcing when loading and CLISP
>>>>loaded fine. Then I can call (nthb 2 '(1 2 3 4)) in CLISP and get

-- 
You will be given a post of trust and responsibility.

---

From: Paul Graham <[email-masked]>
Date: Mon, 30 Jul 2001 07:20:23 -0700 (PDT)

I think both are correct.  I don't think the CL
standard explicitly says that it is an error to write a
macro that expands infinitely.  (Come to think of it, I
wonder if it says anywhere that it is an error to write
ordinary code that goes into an infinite loop.)  If the 
spec had, as it should, said that this was an error, then
implementations could do anything they wanted, unless
the spec said that implementations should *signal* an 
error.  

It would be good if Lisp specs were at least explicit on
what macroexpansion means: i.e. that it is equivalent to
calling a function that returns an s-expression.  That
would make the semantics of macros clearer.

It might actually be an interesting open question what
you should say in a language spec about infinite loops.
I suspect most finesse it.  You can't simply say all outer
loops that don't terminate are in error, or e.g. the
loop operator with no args would be itself illegal.

--pg

> >>>>loaded fine. Then I can call (nthb 2 '(1 2 3 4)) in CLISP and get

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/