-----maxima-bounces at math.utexas.edu wrote: -----
>Maybe?I?am?missing?something,?but?shouldn't?the?following?code?leave?'var'
>undefined? It?works?using?square?brackets?instead?of?local:
>
>var;
>(%o1)?var
>
>func(arg)?:=?block(
>??????local(var),
>??????var:?7,
>??????return(42)
>)$
>
>func(100);
>(%o3)?42
>
>var;
>(%o4)?7
To declare a local variable, use something like this:
(%i1) func(arg) := block([var],
var: 7,
return(42))$
(%i2) func(100);
(%o2) 42
Okay--var doesn't have the value 7:
(%i3) var;
(%o3) var
To learn about 'local,' enter "? local" to read the user documentation. Here is an
example of using 'local':
(%i4) larry(x) := block([var],
var[2] : 5,
42)$
(%i5) larry(100);
(%o5) 42
(%i6) var[2];
(%o6) 5
Now use local
(%i7) george(x) := block([w],
local(w),
w[2] : 5,
42)$
(%i8) george(100);
(%o8) 42
(%i9) w[2];
(%o9) w[2]
I believe that the Maxima translator does not work with local; after compiling
the function 'george', we have a problem:
(%i10) compile(george);
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
(%i11) george(100);
(%o11) 42
Wrong:
(%i12) w[2];
(%o12) 5
--Barton