summaryrefslogtreecommitdiffstats
path: root/tail-recursion.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'tail-recursion.lisp')
-rw-r--r--tail-recursion.lisp22
1 files changed, 12 insertions, 10 deletions
diff --git a/tail-recursion.lisp b/tail-recursion.lisp
index 635982e..8381345 100644
--- a/tail-recursion.lisp
+++ b/tail-recursion.lisp
@@ -252,6 +252,7 @@
(defmacro deftail (name lambda-list &body body)
(let ((escape (gensym "ESCAPE-"))
(other-tails `(,name))
+ (anon-block (gensym))
(docstring)
(decls))
(when (stringp (first body))
@@ -267,13 +268,14 @@
`(defun ,name (,@lambda-list &aux (,escape *tail-escape*))
,@docstring
,@decls
- (flet (,@(loop for other in other-tails
- collecting `(,other (&rest args)
- (return-from ,name
- (let ((*tail-escape* ,escape))
- (tail-call #',other args)))))
- (tail-call (fun args)
- (let ((*tail-escape* ,escape))
- (tail-call fun args))))
- (let ((*tail-escape* nil))
- ,@body)))))
+ (block ,anon-block
+ (flet (,@(loop for other in other-tails
+ collecting `(,other (&rest args)
+ (return-from ,anon-block
+ (let ((*tail-escape* ,escape))
+ (tail-call #',other args)))))
+ (tail-call (fun args)
+ (let ((*tail-escape* ,escape))
+ (tail-call fun args))))
+ (let ((*tail-escape* nil))
+ ,@body))))))