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

Lamy Alain Alain.Lamy at cnes.fr
Fri Nov 30 09:10:32 CET 2012


I understand the logic.
 
My concern was that it is easy to make a mistake
(we write A(5)=1, thinking that the other elements are unchanged and in fact 
everything else is set to 0). 
Arguments to function behave differently (but they are considered as local variables). 

I guess one way could be to add a kind of declaration keywork like:
"import VAR"
whose effect would be to copy the "VAR" variable locally. 
We could even imagine that all variables in a function should either be local are declared 
in some way (some kind of "strict" scilab mode as it exists in perl). 

Maybe a suggestion for future scilab versions ? 
	

-----Message d'origine-----
De : users-bounces at lists.scilab.org [mailto:users-bounces at lists.scilab.org] De la part de Samuel Gougeon
Envoyé : jeudi 29 novembre 2012 22:20
À : International users mailing list for Scilab.
Objet : Re: [Scilab-users] Changing elements of "global" structure/vector in function

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
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users



More information about the users mailing list