[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: portable code walkers



There's a portable code-walker which is part of Portable CommonLoops
which does just what you want. The entry point is

(walk-form form &key walk-function declarations lexical-variables
environment lexical-variables)

The walk-function is like your optional function but it can return a
second value that says whether or not to re-walk; the other keywords are
if you want to pass in some of the other information that the walker
keeps track of.

The code & documentation for it is part of the Portable CommonLoops
release. ("Copyright (c) 1985 Xerox Corporation.  All rights reserved.
Use and copying of this software and preparation of derivative works
based upon this software are permitted.  ...")


I have portable implementations of macrolet, flet, labels, and
compiler-let using the portable code-walker, e.g.

(defmacro compiler-let (vars &rest forms &environment env)
(eval `(special-let ,vars (walk-form `(progn ,@forms) :environment
env))))

where special-let is a macro that expands to a let with all of the
variables declared special. This says to expand all of the macros in
forms while the variables are bound.