Re: Tail recursion syntactic sugar faked with TAGBODY-based construct?



On Jan 31, 5:45 am, Klaus Harbo <kl...@xxxxxxxxx> wrote:
Cute macro.  However, 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)))
                (values (nreverse list)
                        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.

     `(macrolet ,(reverse macrolet-elems)
        (let ,let-bindings
          (argtags nil
                   (return (progn ,@forms))
                   ,@(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.
.



Relevant Pages

  • Re: novice: mapcan use?
    ... This concerned a use of reverse instead of nreverse which could have been safely used. ... Allegro implements the write barrier with a subroutine call. ...
    (comp.lang.lisp)
  • Re: Homework question: LOOP
    ... > "nreverse might either create a new sequence, modify the argument ... (reverse does not modify sequence.)" ...
    (comp.lang.lisp)
  • Re: Homework question: LOOP
    ... If you look up nreverse in CLHS you'll note under Side Effects: ... "nreverse might either create a new sequence, ... (reverse does not modify sequence.)" ... to cons at all. ...
    (comp.lang.lisp)
  • Re: Common Lisps fixable issues?
    ... The main use is that many useful functions can be done with side- ... Both REVERSE and NREVERSE are useful things to ... the NFOO semi-convention is Common Lisp highlights the ...
    (comp.lang.lisp)
  • Re: Homework question: LOOP
    ... it would be perfectly legal to have nreverse be identical to ... >> on a cons and reverse and nreverse both maintain the identity of the ... > sequence, modify the argument sequence, or both." ... > actually modified X while the outer call created a new sequence. ...
    (comp.lang.lisp)