[Maxima] arrays/lists with multi-idices
robert.dodier at gmail.com
Mon Jun 18 23:09:43 CDT 2007
On 6/18/07, Fabrizio Caruso <caruso at dm.unipi.it> wrote:
> Sorry but I don't know hot to force arrays to be local.
> There must be something I am missing.
> For instance:
> foo(x):= block([b],b:make_array('hashed,3),b:x);
> will change b after its execution.
> Moreover I would like to use things like
> b[5,2,3,4] where the number of arguments is a parameter.
Fabrizio, (1) local(a) within a block saves and restores the
properties (including some varieties of arrays) of a when the
block is entered and exited. (2) For Maxima arrays
implemented as Lisp hashtables, the number of indices is
immaterial; a hash key can be a list of indices (or anything).
For Maxima arrays implemented as Lisp arrays,
arraymake and arrayapply might be useful.
foo (x) := block (local (b), array (b, 5), b : x, listarray (b));
=> [#####, 3, #####, #####, #####, #####]
=> (error message, b is not an array)
bar (a, [L]) := arrayapply (a, L);
bar (x, i, j);
=> x[i, j]
bar (x, i, j, k);
=> x[i, j, k]
I'm sorry that this is confusing; various ideas about arrays,
not entirely consistent, accumulated over the decades.
I think now is a good time to reconsider and maybe
clean up some of that stuff.
Maybe if you say more about what you're trying to accomplish
we can give some advice.
More information about the Maxima