Maybe Clojure uses the term "special form" differently than Common
Lisp does, but here's how to think of "special form" in the Common
Lisp sense.
A form that is *NOT* a special form like (F A B C D ...) will either
evaluate:
1. (SYMBOL-FUNCTION F), then A, B, C, D, ... in order from left-to-
right, OR
2. A, B, C, D, ... in order from left-to-right then (SYMBOL-FUNCTION
F)
And, cannot change the lexical environment (add or remove symbols in
the environment).
It is up to the implementation whether (SYMBOL-FUNCTION F) gets
evaluated first or last, but A, B, C, D, ... get evaluated from let to
right in order before F is invoked.
Any form that does not ALWAYS obey that is a "special form".
Examples:
(+ 3 5 (+ 6 7) ii), the form 3 is evaluated, then 5, then (+ 6 7),
then ii, then all of these are passed to (SYMBOL-FUNCTION +) to
execute. This IS NOT a special form.
(IF A B C) does not evaluate both B and C. Thus, it IS a special
form.
The following IS NOT a special form (as long as XX and YY aren't
dynamic variables that we're overriding but rather just local
variables here like it looks) because it always evaluates A and B in
the expected order:
(DEFMACRO WEIRD (A B)
`(LET ((XX ,A))
(LET ((YY ,B))
(DO-SOMETHING (+ XX YY) (- XX YY)))))
(WEIRD (+ 6 7) ii)
The following IS a special form because it does not evaluate A and B
in the expected order:
(DEFMACRO WEIRD-SPECIAL (A B)
`(LET ((YY ,B))
(LET ((XX ,A))
(DO-SOMETHING (+ XX YY) (- XX YY)))))
(WEIRD-SPECIAL (+ 6 7) ii)
The following IS also a special form since it doesn't always evaluate
A and B in the expected order:
(DEFMACRO WEIRD-MAY-BE-SPECIAL (SPECIAL A B)
`(IF ,SPECIAL
(LET ((XX ,A))
(LET ((YY ,B))
(DO-SOMETHING (+ XX YY) (- XX YY))))
(LET ((YY ,B))
(LET ((XX ,A))
(DO-SOMETHING (+ XX YY) (- XX YY)))))
(WEIRD-MAY-BE-SPECIAL (ZEROP (RANDOM 2)) (+ 6 7) ii)
The term "special form" (at least in Common Lisp) has nothing to do
with whether it is built-in or user-defined. It has to do with
whether or not all of its components are evaluated in the expected
order.
ttyl,
Patrick
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en