summaryrefslogtreecommitdiffstats
path: root/tail-recursion.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'tail-recursion.lisp')
-rw-r--r--tail-recursion.lisp27
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)