[Scilab-users] Variable scope in Scilab

Antoine Monmayrant antoine.monmayrant at laas.fr
Mon Mar 1 09:37:18 CET 2021


On 01/03/2021 09:06, Stéphane Mottelet wrote:
>
> Hi Frederico,
>
> I do not have any problem with the variable scoping in Scilab and as I 
> said before, even in Julia there is a similar scoping (at least for 
> the particular case of functions). However, the status of formal input 
> and output parameters should prevent the scoping to apply to them. For 
> example, the following does also work (as an addition to my previous 
> example for the input parameter):
>
> function y=f(x)
> endfunction
>
> y=1
> f
>
> -> f
>  ans  =
>
>    1.
>
> Frankly speaking, allowing such a behavior is madness...
>
Hello Stéphane,

Yes, I think both behaviors you described are non intuitive.

Antoine

> S.
>
> Le 27/02/2021 à 01:33, Federico Miyara a écrit :
>>
>> Stéphane,
>>
>> I agree it shouldn't happen, but the same moment access to outer 
>> variables is granted you can't prevent such thing to happen since 
>> inside the function all variables have a name which is more than just 
>> a symbol or a mute variable, and this includes undefined arguments.
>>
>> This scoping feature is dangerous and I don't think it would be 
>> advisable to create a macro for general use exploiting it.
>>
>> May be someone can provide an example where it has been used with 
>> profit or explain why it was originally introduced
>>
>> Regards,
>>
>> Federico Miyara
>>
>> On 26/02/2021 10:38, Stéphane Mottelet wrote:
>>> 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.
>>>
>>
>>
>> <https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> 
>> 	Libre de virus. www.avast.com 
>> <https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> 
>>
>>
>> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
> -- 
> 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
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210301/1a16d944/attachment.htm>


More information about the users mailing list