From 2e1a18eb896cdbeb278b545576d1ef100bdea12b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 14 Nov 2013 15:01:40 -0800 Subject: TAILPROG: renamed to TLET, loses the variable bindings parameter. Variables are automatically collected from the labels. --- tail-recursion.lisp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'tail-recursion.lisp') 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 ;;; ;;; ;;; 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) -- cgit v1.2.3