[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Macro expansion suggestions
- To: common-lisp at SU-AI
- Subject: Macro expansion suggestions
- From: Howard I. Cannon <HIC at MIT-MC>
- Date: Thu, 28 Jan 1982 23:46:00 -0000
I have sent the following to GLS as a proposal Lambda Macros in for
Common Lisp. It is implemented on the Lisp Machine, and is installed
in Symbolics system 202 (unreleased), and will probably be in MIT
You could easily use them to implement functional programming style,
and they of course work with #' as RMS suggests.
The text is in Bolio input format, sorry.
.section Lambda macros
Lambda macros may appear in functions where LAMBDA would have previously
appeared. When the compiler or interpreter detects a function whose CAR
is a lambda macro, they "expand" the macro in much the same way that
ordinary Lisp macros are expanded -- the lambda macro is called with the
function as its argument, and is expected to return another function as
its value. Lambda macros may be accessed with the (â??3:lambda-macroâ??*
â??2nameâ??*) function specifier.
.defspec lambda-macro function-spec lambda-list &body body
Analagously with â??3macroâ??*, defines a lambda macro to be called
â??2function-specâ??*. â??2lambda-listâ??* should consist of one variable, which
will be the function that caused the lambda macro to be called. The
lambda macro must return a function. For example:
(lambda-macro ilisp (x)
`(lambda (&optional ,@(second x) &rest ignore) . ,(cddr x)))
would define a lambda macro called â??3ilispâ??* which would cause the
function to accept arguments like a standard Interlisp function -- all
arguments are optional, and extra arguments are ignored. A typical call
(fun-with-functional-arg #'(ilisp (x y z) (list x y z)))
Then, any calls to the functional argument that
â??3fun-with-functional-argâ??* executes will pass arguments as if the
number of arguments did not matter.
â??3deflambda-macroâ??* is like â??3defmacroâ??*, but defines a lambda macro
instead of a normal macro.
â??3deflambda-macro-displaceâ??* is like â??3defmacro-displaceâ??*, but defines
a lambda macro instead of a normal macro.
.defspec deffunction function-spec lambda-macro-name lambda-list &body body
â??3deffunctionâ??* defines a function with an arbitrary lambda macro
instead of â??3lambdaâ??*. It takes arguments like â??3defunâ??*, expect that
the argument immediatly following the function specifier is the name of
the lambda macro to be used. â??3deffunctionâ??* expands the lambda macro
immediatly, so the lambda macro must have been previously defined.
(deffunction some-interlisp-like-function ilisp (x y z)
(list x y z))
would define a function called â??3some-interlisp-like-functionâ??*, that
would use the lambda macro called â??3ilispâ??*. Thus, the function would
do no number of arguments checking.