CL -- Common Lisp
EL -- Emacs Lisp
Having now read "Macros in Scheme" and
the first four parts of "An
Introduction To Macro Expansion Algorithms" I am still not convinced
that
CL's macro facility is in such shambles. It seems that Scheme's
need for
"hygenic" macros comes from its "feature" of having each
symbol name a
variable or a function, but not both simultaneously and
its apparent lack
of CL style packages.
One example that shows the "symbol names function"
vs "symbol names
variable" problem is
(let ((cons '()))
(push "ghengis"
cons)
(push "khubla" cons)
cons)
This is a problem in Scheme because
CONS is defined to be a function
for constructing lists. Within this LET
it is rebound to be a
variable holding an empty list. In CL, function and
variable bindings
are separate. CONS is defined as a function by the standard, but carries
no variable definition [it is unbound], therefore, LET is free to establish
a local variable binding for CONS and PUSH will not be confused because it
will use the function binding for CONS. This form evaluates correctly in
CL and EL.
One example that can be fixed by use of packages is [Scheme
form]:
(let* ((cons (lambda (name)
(case name
((phil)
'("three-card monte"))
((dick) '("secret plan to end the war"
"agnew"
"not a crook"))
((jimmy) '("why not the best"))
((ron)
'("abolish the draft"
"balance the budget"))
(else '()))))
(scams (cons 'phil)))
(push (car (cons 'jimmy)) scams)
(push (cadr
(cons 'ron)) scams)
scams)
If the application really needs a function
named CONS with different
behavior that CL's CONS, a new package should be
defined which shadows
the CONS symbol [CL form]:
(defpackage FOO
(:use
CL)
(:shadow CONS))
(in-package :FOO)
(labels ((cons (name)
(case
name
((phil) '("three-card monte"))
((dick) '("secret plan to
end the war"
"agnew"
"not a crook"))
((jimmy) '("why not the
best"))
((ron) '("abolish the draft"
"balance the budget"))
(t nil))))
(let ((scams (cons 'phil)))
(push (car (cons 'jimmy))
scams)
(push (cadr (cons 'ron)) scams)
scams)
Now, when CONS is
seen in the code, one will know that it is the
application's definition.
When CL:CONS is seen, one will know that it
is CL's definition.
Craig Lanning
E-Mail: CraigL(a)InternetX.net
Show replies by date