define hashed array elements



On Mon, Sep 28, 2009 at 3:17 PM, Edwin Woollett <woollett at charter.net> wrote:

> (%i2) def4vec (a, a0, a1, a2, a3) := block (
> ? ? ? ? ? ? ? a[0] : a0,
> ? ? ? ? ? ? ? a[1] : a1,
> ? ? ? ? ? ? ? a[2] : a2,
> ? ? ? ? ? ? ? a[3] : a3 )$

I guess this a job for the undocumented function arraysetapply,
which evaluates the name of the array (as a[0] : ... does not).

Try this:

def4vec (a, a0, a1, a2, a3) :=
 (arraysetapply (a, [0], a0),
  arraysetapply (a, [1], a1),
  arraysetapply (a, [2], a2),
  arraysetapply (a, [3], a3));

Does that have the intended effect?

Maxima is more than a little bit confused about whether or
not to evaluate the name of a function or array; sometimes
it does and sometimes not.

best

Robert Dodier