diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-11-14 15:01:40 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-11-14 15:01:40 -0800 |
commit | 2e1a18eb896cdbeb278b545576d1ef100bdea12b (patch) | |
tree | b45dd7f108602c17af56d061621e76dbeb327398 | |
parent | a4d671b27b30352476e81efacd8c15de349382c1 (diff) | |
download | lisp-snippets-2e1a18eb896cdbeb278b545576d1ef100bdea12b.tar.gz lisp-snippets-2e1a18eb896cdbeb278b545576d1ef100bdea12b.tar.bz2 lisp-snippets-2e1a18eb896cdbeb278b545576d1ef100bdea12b.zip |
TAILPROG: renamed to TLET, loses the variable bindings parameter.
Variables are automatically collected from the labels.
-rw-r--r-- | tail-recursion.lisp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/tail-recursion.lisp b/tail-recursion.lisp index 9bdf0b3..b963d49 100644 --- a/tail-recursion.lisp +++ b/tail-recursion.lisp @@ -1,6 +1,6 @@ ;;; -;;; ARGTAGS, TAILPROG and DEFTAIL -;;; Copyright 2012 Kaz Kylheku +;;; ARGTAGS, TLET and DEFTAIL +;;; Copyright 2013 Kaz Kylheku ;;; <kaz@kylheku.com> ;;; ;;; This Lisp source contains three ideas which reveal tail recursion @@ -8,7 +8,7 @@ ;;; which disguise goto behind a more disciplined interface ;;; which resembles function calling. ;;; -;;; First ARGTAGS is presented. Then a macro called TAILPROG which +;;; First ARGTAGS is presented. Then a macro called TLET which ;;; builds a slightly higher level abstraction on ARGTAGS. ;;; ;;; Finally a scheme, no pun intended, for cross-module tail calling @@ -142,10 +142,11 @@ ;;; -;;; TAILPROG -;;; ======== -;;; -;;; (Thanks to Klaus Harbo for some fixes). +;;; TLET +;;; ==== +;;; +;;; (Thanks to Klaus Harbo for some fixes. to the original version +;;; which was called TAILPROG). ;;; ;;; This macro provides wraps more syntactic sugar around ARGTAGS, ;;; giving rise to a syntax which resembles the Lisp LABELS. @@ -158,15 +159,17 @@ ;;; the value of such a call, it still does not return. ;;;; -(defmacro tailprog (let-bindings pseudo-funcs &rest forms) - (let (argtags-forms macrolet-elems) +(defmacro tlet (pseudo-funcs &rest forms) + (let (argtags-forms macrolet-elems var-list) (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))) + (push `(,name (&rest args) `(goto ,',name ,@args)) macrolet-elems) + (dolist (var vars) + (push var var-list)))) `(macrolet ,(reverse macrolet-elems) - (let ,let-bindings + (let ,var-list (argtags nil (return (progn ,@forms)) ,@(reverse argtags-forms)))))) @@ -231,7 +234,7 @@ ;;; ;;; This is still a GOTO-like abstraction, because tail calls are tail ;;; calls even if they are not in a tail position. They never return, -;;; just like in TAILPROG. +;;; just like in TLET. ;;; (defvar *tail-escape* nil) |