Subject: [clisp-list] Re: Recursive macros

From: Bruce <[email-masked]>
Date: Thu, 05 Jul 2001 11:25:20 +0800

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 3.

Best!

> --- Bruce <[email-masked]> wrote:
> 
>>While reading Dr. Graham's book, "On Lisp", I found it difficult to 
>>appreciate the difference between two recursive macros that he said
>>one 
>>is bad and the other is good.
>>
>>Bad one (P.140):
>>(defmacro nthb (n lst)
>>   `(if (= ,n 0)
>>        (car ,lst)
>>      (nthb (- ,n 1) (cdr ,lst))))
>>
>>Good one (P.142):
>>(defmacro orb (&rest args)
>>   (if (null args)
>>       nil
>>     (let ((sym (gensym)))
>>       `(let ((,sym ,(car args)))
>>          (if ,sym
>>              ,sym
>>            (orb ,@(cdr args)))))))
>>
>>It is clear to see that both macros are recursive. Dr. Graham said in
>>
>>the book that the good one is good because it recurses on the
>>arguments 
>>to the macro, not on the values of the arguments. That seems to make
>>sense.
>>
>>But when I tested on CLISP and CMUCL, I found that CLISP happily
>>accepts 
>>both macros but CMUCL runs in endless loop with the bad one.
>>
>>My question is: Is CLISP doing the right thing or CLISP
>>implementation 
>>more conformant to the new ISO standard (Dr. Graham's statement no 
>>longer holds)?