I test the code
L:=[2,1];
sum('a||b*L[1]', 'b' = 1 .. 2);
It returns a1*L[1]+a2*L[1]
, but I expect to get a1*2+a2*2
after evaluation of L[1]
.
Any ideas?
Thanks.
EDIT:
I have one further question. Here's the test code:
L := [2, 1]
test := proc (i) local a1; a1 := 1; add(a || b*L[i], b = 1 .. 2) end proc
test(1);
will result
2 a1 + 2 a2
without evaluating a1
which is a local variable defined in function test.
I expect to get 2*1+2*a2
. Any further idea?
Your first line is just an equation, with =
, and not an actual assignment with :=
. So you weren't doing an assignment to L
.
And the uneval quotes are misapplied, in the sum
call, and wrap too much.
You could also use add
instead of sum
, to rely on the special evaluation rules of add
and thus get rid of the need for the uneval quotes.
> L:=[2,1];
L := [2, 1]
> add(cat(a,b)*L[1], b = 1 .. 2);
2 a1 + 2 a2
> add((a||b)*L[1], b = 1 .. 2);
2 a1 + 2 a2
> sum('a||b'*L[1], 'b' = 1 .. 2);
2 a1 + 2 a2
> sum('cat(a,b)'*L[1], 'b' = 1 .. 2);
2 a1 + 2 a2