PgUtils
PgUtils is a package containing all the utility functions and macros from Paul Graham's excellent On Lisp book.

Download (archived because the original server is unreliable): http://ftp.linux.org.uk/pub/lisp/cclan/pgutils.tar.gz

Quick assessment (2023-02-23)

Broken because the code was originally written before symbol-macrolet was standardized:

#+(or cltl2 symbolics) ; LMH (defmacro alrec (rec &optional base) "Anaphoric list recurser (lrec): use `it' to refer to the current car of the list, and `rec' to the function rec itself. every on #'oddp, (alrec (and (oddp it) rec) t) is the equivalent of (lrec #'(lambda (x f) (and (oddp x) (funcall f))) t)." ; LMH (let ((gfn (gensym))) `(lrec #'(lambda (it ,gfn) (declare (ignorable it) (function ,gfn)) ; LMH (#+cltl2 symbol-macrolet #+symbolics clos:symbol-macrolet ((rec (funcall ,gfn))) ,rec)) ,base))) #-(or cltl2 symbolics) ; LMH -- I don't think this works (defmacro alrec (rec &optional base) "Anaphoric list recurser (lrec): use `it' to refer to the current car of the list, and `rec' to the function rec itself. every on #'oddp, (alrec (and (oddp it) rec) t) is the equivalent of (lrec #'(lambda (x f) (and (oddp x) (funcall f))) t)." ; LMH (let ((gfn (gensym))) `(lrec #'(lambda (it ,gfn) (declare (ignorable it) (function ,gfn)) ; LMH (labels ((rec () (funcall ,gfn))) ,rec)) ,base))) (defmacro on-cdrs (rec base &rest lsts) "Anaphoric list recursion, for defining named functions, e.g., (defun our-every (fn lst) (on-cdrs (and (funcall fn it) rec) t lst))." ; LMH `(funcall (the function (alrec ,rec #'(lambda () ,base))) ,@lsts)) ; LMH the function

The actual code from the book is:

(defmacro alrec (rec &optional base) "cltl2 version" (let ((gfn (gensym))) `(lrec #'(lambda (it ,gfn) (symbol-macrolet ((rec (funcall ,gfn))) ,rec)) ,base))) (defmacro alrec (rec &optional base) "cltl1 version" (let ((gfn (gensym))) `(lrec #'(lambda (it ,gfn) (labels ((rec () (funcall ,gfn))) ,rec)) ,base))) (defmacro on-cdrs (rec base &rest lsts) `(funcall (alrec ,rec #'(lambda () ,base)) ,@lsts))

So this was given as a CLtL2 technique pre-ANSI.


obsolete