making for-loops more general. Was: Re: New version of makelist
Subject: making for-loops more general. Was: Re: New version of makelist
From: Barton Willis
Date: Mon, 26 Apr 2010 06:20:16 -0500
-----maxima-bounces at math.utexas.edu wrote: -----
>I?notice?that?the?for-loop?stuff?does?NOT?permit?the?index?to?be?(say)???
>x[k].?Is?this?really useful???
This prohibition is good. It's tempting to use x[1], x[k], ... as
ordinary variable names, but if the implicitly defined hashed array x
is assigned a value, the code might misbehave. Also, the Maxima translator
generates bogus code for hashed arrays that are declared local (at the
least the translator alerts the user)
(%i1) bob() := block([x], local(x), x[1] : 42)$
(%i2) translate(bob)$
Local does not work well in translated code.
Try to use value cell and the Use_fast_arrays:true
if this is for arrays. For functions, local definitions are
not advised so use lambda expression
(%i3) x[1];
(%o3) x[1]
(%i4) bob();
(%o4) 42
(%i5) x[1];
(%o5) 42
And explain this:
(%i1) (a : b, b : c, c : d)$
(%i2) [a,a[1]];
(%o2) [b,d[1]]