Enforcing Syntax for function/macro



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.

.



Relevant Pages

  • Re: Count Lines in (Huge) Text Files
    ... A few years ago, I was doing some high-throughput disk stuff and my recollection is that I found the same thing you did: larger buffers only helped up to about 8K or so, and past that any improvement was minimal. ... me that with appropriate settings for its buffer, it should perform better, since it ought to be optimized for line-based i/o. ... Assuming what's hurting you in the explicit forloop is the retrieval of the data and not the counter increment, the above should perform basically as well as a plain foreach() loop. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: Lost data on socket - Can we start over politely?
    ... $clsel as a single-element-holding object containing the current ... simply performing the following check on $sel instead of $clsel? ... removing elements from something from a list used for the loop is a Bad ... Doesn't that throw the foreach() loop out of sync? ...
    (comp.lang.perl.misc)
  • Re: foreach statement output
    ... > I'm still trying to get an understanding of the way a foreach loop loops. ... You can't use the loop variable as an index to your array. ...
    (comp.infosystems.www.authoring.cgi)
  • Re: array and hash patter matching
    ... however I am struggling on how to compare the hash with an array for any ... Why are you using this foreach loop inside the while loop? ... client_list is a list of one or more host names, host addresses, ...
    (perl.beginners)