From: ·······@gmail.com
Subject: Enforcing Syntax for function/macro
Date: 
Message-ID: <1188483598.515522.160750@50g2000hsm.googlegroups.com>
 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.
From: Pascal Bourguignon
Subject: Re: Enforcing Syntax for function/macro
Date: 
Message-ID: <87abs9yq9w.fsf@mini.informatimago.com>
·······@gmail.com 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.