Re: Enforcing Syntax for function/macro
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Aug 2007 17:51:23 +0200
srallya@xxxxxxxxx writes:
I was looking a bit at the CLisp implementation yesterday and noticed
that the way that the (loop) is implemented allows for things such as:
(loop initially for i from 1 to 5 do (print i) finally return i)
and:
(loop for x on y finally (return x))
My question is how would you enforce the use of certain keywords
such as initially, finally, on, and so forth within a function or a
macro considering they're syntactical sugar so to speak and not
functions themselves?
Exactly, how would you do it?
(defmacro mine (&rest r)
(print r)
'nil)
C/USER[8]> (macroexpand-1 '(mine how do you parse this?))
(HOW DO YOU PARSE THIS?) ;; printed at macroexpansion time.
NIL ; ;; expansion, executed at run time.
T
[...]
Sorry if the question itself is unclear, a bit hard-pressed to
explain it in a way that would make what I'm trying to ask clearer.
The example I gave might be a poor one as well, but hopefully you can
see from the loop example a bit more what I'm getting at.
Remember, a macro is a function like any other.
Your problem is that you have a symbolic expression, a list of items,
and you need to find the keywords and the sub-expressions in it to
build a new symbolic expression to return to the compiler for
compilation. Surely you can write such a simple function.
--
__Pascal Bourguignon__ http://www.informatimago.com/
COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.
.
- References:
- Enforcing Syntax for function/macro
- From: srallya
- Enforcing Syntax for function/macro
- Prev by Date: Re: gc bug is SBCL?
- Next by Date: Re: rotatef mystery
- Previous by thread: Enforcing Syntax for function/macro
- Next by thread: rotatef mystery
- Index(es):
Relevant Pages
|