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: Kaz Kylheku 2012-01-19 1:24

Hi, I wrote TAILPROG originally and the above unattributed cut and paste is incomplete. Note that the macro expands to another macro called ARGTAGS.  This stuff is now hosted in a GIT repository.  http://www.kylheku.com/cgit/cgit.cgi/lisp-snippets/tree

In tail-recursion.lisp, I also included DEFTAIL, which is a way to have tail recursion between functions not in the same scope (even in separate source files). It uses dynamic non-local control transfers and a hidden dispatch loop.

These constructs are different from tail recursion and are useful even if you have it from your compiler. One big difference is that the calls are always tail calls, no matter their position in the expression. (I.e. they are not just tail calls in a tail position!)

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