Re: Enforcing Syntax for function/macro



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.
.



Relevant Pages

  • Re: hanging macros
    ... >> won't work unless the compiler knows the definition of A at the ... Recently I had occasion to use macros in a loop ... What I wanted was a macro expanding into something like ... macro output spliced into an existing loop form. ...
    (comp.lang.lisp)
  • Re: definite integral
    ... in the while loop so that i have a range of g values)i change x into a ... SUBS numeric values for x into the symbolic expression g, ... then PLOT the double array. ... Take a look at the HELP for any of the words in all caps above for more ...
    (comp.soft-sys.matlab)
  • Re: A whole lotta WRITE_REGISTER_ULONG
    ... WRITE_REGISTER_ULONG _may_ be a macro in some configurations. ... And without 'volatile' qualifier, the compiler might optimize the whole ... write loop down to the last write, which would not work for OP. ...
    (microsoft.public.development.device.drivers)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... >> both less efficient and less safe than the Fortran and Basic standard. ... >> The C for loop is actually trying to do what a do loop does. ... sloppy thinking that results from confusing a programming language ... > I do not believe that you are capable of writing a conforming C compiler. ...
    (comp.programming)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... it's a for loop in the C sense. ... > sloppy thinking that results from confusing a programming language ... >> I do not believe that you are capable of writing a conforming C compiler. ... Does Microsoft's C compiler perform this optimisation? ...
    (comp.programming)