[Scilab-users] Changing elements of "global" structure/vector in function

Samuel Gougeon sgougeon at free.fr
Thu Nov 29 22:20:16 CET 2012


Le 29/11/2012 12:46, Lamy Alain a écrit :
> Changing elements of a "global" (i.e. visible) variable in a function may be dangerous.
> A new structure or vector is created that only contains the elements that have been changed.
>
> I would expect the whole structure/vector to be copied locally before changing part of them.
>
> A workaround is to create a local copy in the function by an instruction like:
> A=A
> (see fun3)
> which looks a bit strange at first sight as it seems to do nothing.
>
> Has anyone an opinion on whether this is considered as correct behaviour or not ?
> Or is it a bug ?
AFAIU, i do not think that it is a bug.
When a LHS symbol is not yet defined, then Scilab creates it as a recipient.
It is the usual behavior. While if a RHS symbol is not yet defined,
the expected source is missing, and rather than yielding an error, Scilab
tries to look for it outside. Then, the "global"  link is set.

So, this could look tricky, but yes: A=A does it ;-)

Samuel



More information about the users mailing list