Local variables not so local within block



I've tried your implementation of "blex". It seems to work fine, do you
think it could be used in a (more or less) stable code? Anyway it doesn't
support the "return" statement, Maxima complains that return is not inside
a block.

But, reading the documentation of block, I've just discovered the "local"
command, wich seems to solve the problem. If I modify the previous function
to

f(x):=block(local(a),a:zeromatrix(2,1),a[1,1]:x);

the problem disappears. I'm wondering if this could be a correct/safe
approach for writing complex codes with lots of functions. Could it be used
to completely replace the list of local variables contained in the list at
the begin of a block?

Thanks
Stefano



2012/7/23 Robert Dodier <robert.dodier at gmail.com>

> Stefano Ferri <ferriste <at> gmail.com> writes:
>
> > Thanks for your reply. I've followed some discussions on the
> > mailing list in the past about some inconsistencies with the block
> > construct, but the problems were related to the arguments passed
> > to functions (e.g. f(x):=block([],....) in wich x was not really
> > local).
>
> As it happens, in Maxima, function arguments are local variables
> in exactly the same way that variables in block are local.
>
> >> Furthermore, Maxima's implementation of Lisp-2-ness is messy.
>
> > Isn't this a bug?
>
> Yes.
>
> > I always give different names to different kind of variables,
> > because I had some problems in the past with lists and undeclared
> > arrays with the same, so I started to use different names. But if
> > one writes a program and it grows and becomes more complex, there
> > will be a lot of functions and functions calling other functions,
> > and it becomes difficult to always use different names and remember
> > wich have been used, when this names should be local.
>
> Yes, that's a very good argument for lexical scope -- it
> makes large programs more comprehensible.
>
> > I read about blex, but it use gensym, right? If so, wich is the
> > minimum Maxima version working with blex?
>
> Well, the implementation I recently posted
> (http://permalink.gmane.org/gmane.comp.mathematics.maxima.general/38899)
> doesn't depend on the existence of a Maxima gensym function.
>
> best
>
> Robert Dodier
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>