Hello,
I am just writing a tutorial about macros in Maxima. I have found the following problem:
(C1) foo(x)::= block( [x:ev(x)], print(x) )$
(C2) block( [a:1], foo(a) );
1 (this is what I want)
(D2) 1
(C3) block( [x:1], foo(x) );
x (not wanted)
(D3) 1
So if I use the name of the variable, which is inside the macro definition, it works wrong.
This seems to be some kind of variable capture. Is this a bug or just the macro
mechanism? ( remark: It is hard to read 'defun mdefmacro1' because it uses a lot of not
documented macsyma functions. )
A way out could be to use a gensym-like variable in the situations of using 'ev' inside of
a macro definition.
(C7) foo(x49291)::= block( [x49291:ev(x49291)], print(x49291) )$
(C8) block( [x:1], foo(x) );
1
(D8) 1
Or are there any other possibilities?
One example: (setting variables parallel)
(C9) parallel(x,y,u,v)::= buildq(
[ x,y:ev(y), u,v:ev(v) ],
block(x:y, u:v) )$
(C10) block( [a:1,b:2], parallel(a,b,b,a), [a,b] );
(D10) [2, 1]
(C11) block( [x:1,y:2], parallel(x,y,y,x), [x,y] );
(D11) [2, 2]
this looks ugly, but it works:
(C12) parallel(x33657,y25179,u65757,v17302)::= buildq(
[ x33657, y25179:ev(y25179), u65757, v17302:ev(v17302) ],
block( x33657:y25179, u65757:v17302 ) )$
(C13) block( [x:1,y:2], parallel(x,y,y,x), [x,y] );
(D13) [2, 1]
Any comments?
Volker van Nek