Enforcing Syntax for function/macro
- From: srallya@xxxxxxxxx
- Date: Thu, 30 Aug 2007 14:19:58 -0000
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?
So, for example, lets say I wanted to provide
(foreach x in '(1 2 3 4 5) do
(
(+ 1 x)
(print x)))
Now, I wrote a macro last night that sort of did this
(defmacro foreach (x in list do body)
`( ...... ))
First of all, "in" and "do" are not used within the macro body at all,
only x, list, and body. This allowed me to write (foreach x in '(1 2
3) do (print x)), but then again I could have replace "in" and "do"
with anything and it would still work. Of course, with all aside that
you could just do (foreach (x list body)) which would be easier and
better to do, is there a way to enforce those 'keywords'? Furthermore,
could you tie in those key words with functionality themselves? So
"in" might be distinguished from other keywords that modify the way
the function/macro operates?
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.
.
- Follow-Ups:
- Re: Enforcing Syntax for function/macro
- From: Pascal Bourguignon
- Re: Enforcing Syntax for function/macro
- Prev by Date: Re: Floyd Warshall
- Next by Date: Re: Floyd Warshall
- Previous by thread: Passing Global Variables Urgh.
- Next by thread: Re: Enforcing Syntax for function/macro
- Index(es):
Relevant Pages
|