For Programmers: Free Programming Magazines  


Home > Archive > Lisp > January 2008 > Re: Tail recursion syntactic sugar faked with TAGBODY-based









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Tail recursion syntactic sugar faked with TAGBODY-based
Kaz Kylheku

2008-01-31, 7:29 pm

On Jan 31, 5:45=A0am, Klaus Harbo <kl...@harbo.net> wrote:
> Cute macro. =A0However, TAILPROG relies on NREVERSE not messing up ARGTAGS=

-FORMS and MACROLET-ELEMS (which it is permitted
> to do according to the standard), in LW5.1-beta I get
>
> CL-USER 12 > (let ((list '(1 2 3)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (values (nreverse list)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 list))


Yes of course. NREVERSE can rearrange the CONS structure without
moving around the CAR fields.

Of course, I intended this:

(setf argtags-forms (nreverse argtags-forms))

my Lisp just let me get away without the SETF, because it implements
reversal by reshuffling CAR's.

> =A0 =A0 =A0`(macrolet ,(reverse macrolet-elems)
> =A0 =A0 =A0 =A0 (let ,let-bindings
> =A0 =A0 =A0 =A0 =A0 (argtags nil
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(return (progn ,@forms))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0,@(reverse argtags-forms))))))
>
> instead -- that seems to work.


NREVERSE should also work here. But then if I'm going to obsess over
consing in REVERSE, then to be consistent I should also be using ,.
rather than ,@ for instances of splicing not in a tail position.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com