Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

TAILPROG

Name: Anonymous 2010-01-31 11:01


(defmacro tailprog (let-bindings pseudo-funcs &rest forms)
  (let (argtags-forms macrolet-elems)
    (dolist (pfunc pseudo-funcs)
      (destructuring-bind (name vars &rest forms) pfunc
        (push `(label ,name ,@vars) argtags-forms)
        (push `(return (progn ,@forms)) argtags-forms)
        (push `(,name (&rest args) `(goto ,',name ,@args)) macrolet-elems)))
    `(macrolet (,.(nreverse macrolet-elems))
       (let ,let-bindings
         (argtags nil
           (return (progn ,@forms))
           ,.(nreverse argtags-forms))))))

ALL YOUR TAIL RECURSION R BELONG TO US

Name: Anonymous 2010-02-01 3:56

I've seen this on c.l.l. sometime ago:
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/6d41174f80d5427b/
It's an interesting macro, since TCO is supported in most major CL implementations, it's less useful.
>>6
Unlike Scheme, CL has many iterative constructs, and they have no need to force what optimizations compilers must make. TCO is a good optimization, and is supported by most real CL implementations, which means that in practice you can write tail-recursive code as much as you'd like.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List