[Scilab-Dev] [Scilab-users] Variable scope in Scilab
Stéphane Mottelet
stephane.mottelet at utc.fr
Fri Feb 26 14:50:00 CET 2021
Hi devs,
Just after changing the rule in macro.cpp I see this at startup, and I
am laughing out loud ;-)
Scilab branch-6.1 (Feb 19 2021, 14:37:51)
at line 44 of function mdelete (
/Users/mottelet/git/scilab_6.1.orig/scilab/modules/fileio/macros/mdelete.sci
line 57 )
at line 26 of function atomsAUWriteAccess (
/Users/mottelet/git/scilab_6.1.orig/scilab/modules/atoms/macros/atoms_internals/atomsAUWriteAccess.sci
line 42 )
at line 11 of function atomsSystemInit (
/Users/mottelet/git/scilab_6.1.orig/scilab/modules/atoms/macros/atomsSystemInit.sci
line 27 )
Wrong number of input arguments.
-->
Does it mean that we use the "crappy shortcut" as a feature in Scilab
internals ?
S.
Le 26/02/2021 à 14:38, Stéphane Mottelet a écrit :
> Hi all,
>
> In Scilab the scope of variables is quite permissive but even in Julia
> (really strict rules) we can have the following behavior:
>
> function y=f(x)
> y=x+a;
> end
>
> a=1;
> f(2)
> a=2;
> f(3)
>
> -> a=1;
>
> --> f(2)
> ans =
>
> 3.
>
> --> a=2;
>
> --> f(3)
> ans =
>
> 5.
>
> Yesterday afternoon I was my students for a Scilab beginners tutorial,
> and by accident one of them had "x" defined before in the main
> workspace and tried to call f without arguments. I reproduce the
> experiment here by explicitely defining x before the call:
>
> x=1;
> f
>
> --> x=1;
>
> --> f
> ans =
>
> 3.
>
> Allowing the function inner scope to see variables of the outer scope
> is one thing, you may or may not agree this is not the point here, but
> allowing to call f without arguments just because the formal input
> parameter has the same symbol as an outer scope symbol is another
> thing. I knew this was possible even if i never used such a feature,
> but my students were so puzzled by this, particularly those who
> already learned other low-level languages, that I decided to propose
> the suppression of this, that I consider as a serious potential source
> of many bugs. Don't tell me that this would break some user code
> because I frankly have no consideration for this kind of crappy
> shortcut and, sorry if it may sound rude, for programmers who use it...
>
> S.
>
--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
More information about the dev
mailing list