about local statements inside block



On 6/18/08, Valery Pipin <pip at iszf.irk.ru> wrote:

>  Am I right to expect that local declaration like, e.g.,
>  f(a):=block(local(y),y:2, a*y);
>  will declare variable y to belong to that block only?

Not exactly. The "local" function saves & restores symbol properties,
but not the symbol value. block([y], ...) saves & restores the value.

Maxima stores a lot of stuff as symbol properties, e.g. function
definitions. In this example "local" makes a local function definition.

foo (x) := 17 * x;
bar (y) := block (local (foo), foo (x) := x - 29, foo (y));
foo (10);
 => 170
bar (10);
 => -19
foo (10);
 => 170

HTH

Robert Dodier