stumped on a macro

From: David Wallis (dww_at_dwws-computer.local)
Date: 03/28/05


Date: Mon, 28 Mar 2005 17:52:01 +0100


I'm trying to write my first non-trivial macro, and it's had me stumped
for about 3 weeks. Can anyone help?

I contacted the list a while back about implementing operators to do array
arithmetic. I got that working (see www.cpom.org/nlisp/index.html), but I
want to re-do them as macros instead of functions and I'm struggling.

I want to write expressions like the following (Note (.iseq a b) is a
function that returns an array of numbers between the a and b. I'm just
using .iseq as an example of something that will return an array. It's not
important to the problem).

(.+ (.iseq 1 10) 3d0 (.iseq 11 20))

And I want .+ to be a macro that will expand the above to something like:

(let ((r (make-array 10 :element-type '(complex double-float)))
       (a (.iseq 1 10))
       (b 3d0)
       (c (.iseq 11 20)))
    (dotimes (i 10)
       (setf (aref r i) (+ (aref a i) b (aref c i)))) r)

(Of course, for the real code, I should use gensyms, and I'll have a load
of type declarations etc. for efficiancy).

One advantage of using a macro is that I want to get the array size at
compile time to pass to make-array and for the dotimes loop. This will
save doing them at run time and will speed it up no end. I can't think of
any reason why this shouldn't be possible.

The macro has to look at each argument that I pass and insert either (aref
x i) or just x, depending on the 'type' of the argument (if it's an array
or a scaler) in the last line.

Here's the problem. If I have a function called .+ and call it like this:

(.+ (.iseq 1 10) 3d0)

lisp will evaluate the call to .iseq and pass to .+ an array and 3d0. With
a macro call, the .iseq will not be evaluated, so the macro will get the
expression (.iseq 1 10) and not the value.

So, if I don't have the values of the arguments, how can I find the type
and array size? Or to put it another way, I need to evaluate the arguments
to the macro to expand it.

My final macro will probably take a function as the fist argument, so I
can define functions like .+ at compile time with any array dimensions and
combination of array and scaler arguments. Or even pass a lambda
expression and some arguments. Any function that operates on scaler
arguments will do, and the macro writes the appropriate loop. This is all
easy if I can just solve the current problem.

If anyone can suggest a solution or offer any help, I would be very
greatful. Maybe my whole approach is wrong?



Relevant Pages

  • Array and Struct Constants in MASM
    ... compile-time array and structure constants. ... Syntax (used as a macro function): ... This macro creates a MASM struct declaration and also creates ...
    (alt.lang.asm)
  • Re: Help end the testing tedium please
    ... The new macro is crashing at: ... The filename and sheet name look fine. ... two arguments needed for "Consolidate". ... the file really were test1 thru test60, would the array statement need ...
    (microsoft.public.excel.programming)
  • Re: Is it possible to run a macro in tandem with, or right after,
    ... macro, or by having one macro call several others that each perform one piece ... 'sub procedure can access the rowHgts array from this ... Dim rowRng As Range ... Dim outputRow As Long ...
    (microsoft.public.excel.programming)
  • Re: Code wont execute Main Macro Calls - non breaking spaces
    ... I am going to attach my first array which is the same as you have ... So each macro will execute one after the other. ... separated each find string and each replace string for the sake of ...
    (microsoft.public.word.vba.general)
  • Re: Difference between C and advanced C
    ... static and type qualifiers in parameter array declarators ... trailing comma allowed in enum declaration ... additional predefined macro names ... additional strftime conversion specifiers ...
    (comp.lang.c)