[Scilab-users] Variables visibility in functions

classic Classic list List threaded Threaded
7 messages Options
kjubo kjubo
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Variables visibility in functions

Dear all,

I would like to ask you, how can I disable visibility of variables from
workspace for functions.

I need to be sure, that function which I convert from script file, will not
use any variable, which is not in it input, or defined inside the function
itself.

Please see examples below.

Is this possible?
       
Thank you
       
BR
       
JK

        example 1:

        a = 3
        function fx = some_fun(x,a)
            fx = x+a
        endfunction

        calling some_fun(5) now return 3+5, but I need to be an error.


        example 2:

        a = 3
        function fx = some_fun(x)
            fx = x+a
        endfunction

        I need also error, as variable a should be passed as input argument
or defined inside some_fun body



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

Hi,

Use Scilab slint tool:

https://help.scilab.org/docs/6.1.0/en_US/slint.html

S.

Le 07/05/2020 à 14:01, kjubo a écrit :

> Dear all,
>
> I would like to ask you, how can I disable visibility of variables from
> workspace for functions.
>
> I need to be sure, that function which I convert from script file, will not
> use any variable, which is not in it input, or defined inside the function
> itself.
>
> Please see examples below.
>
> Is this possible?
>          
> Thank you
>          
> BR
>          
> JK
>
>          example 1:
>
>          a = 3
>          function fx = some_fun(x,a)
>              fx = x+a
>          endfunction
>
>          calling some_fun(5) now return 3+5, but I need to be an error.
>
>
>          example 2:
>
>          a = 3
>          function fx = some_fun(x)
>              fx = x+a
>          endfunction
>
>          I need also error, as variable a should be passed as input argument
> or defined inside some_fun body
>
>
>
> --
> Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> 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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

In reply to this post by kjubo
Hello,

I am not sure to understand what you want to achieve here.
It is not really clear for me.
You might be able to hack something using 'exists" but I am not sure
that it would fit nicely with the way Scilab is designed...


Antoine


On 07/05/2020 14:01, kjubo wrote:

> Dear all,
>
> I would like to ask you, how can I disable visibility of variables from
> workspace for functions.
>
> I need to be sure, that function which I convert from script file, will not
> use any variable, which is not in it input, or defined inside the function
> itself.
>
> Please see examples below.
>
> Is this possible?
>          
> Thank you
>          
> BR
>          
> JK
>
>          example 1:
>
>          a = 3
>          function fx = some_fun(x,a)
>              fx = x+a
>          endfunction
>
>          calling some_fun(5) now return 3+5, but I need to be an error.
>
>
>          example 2:
>
>          a = 3
>          function fx = some_fun(x)
>              fx = x+a
>          endfunction
>
>          I need also error, as variable a should be passed as input argument
> or defined inside some_fun body
>
>
>
> --
> Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

In reply to this post by mottelet

Here is a small example. Although the name of fields of returned struct is very cryptic, the information you need can be easily recovered.


mputl(["function [y] = foo(x)"
"y = x + a"
"y = y + b"
"endfunction"],"slint_test.sci")

out = slint("slint_test.sci",%f)

if isfield(out.info,"00003.Uninitialized")
    s = out.info("00003.Uninitialized");
    for i=1:length(s)
        disp(s(i).msg)
    end
end

S.

Le 07/05/2020 à 14:40, Stéphane Mottelet a écrit :
Hi,

Use Scilab slint tool:

https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/help.scilab.org/docs/6.1.0/en_US/slint.html

S.

Le 07/05/2020 à 14:01, kjubo a écrit :
Dear all,

I would like to ask you, how can I disable visibility of variables from
workspace for functions.

I need to be sure, that function which I convert from script file, will not
use any variable, which is not in it input, or defined inside the function
itself.

Please see examples below.

Is this possible?
         Thank you
         BR
         JK

         example 1:

         a = 3
         function fx = some_fun(x,a)
             fx = x+a
         endfunction

         calling some_fun(5) now return 3+5, but I need to be an error.


         example 2:

         a = 3
         function fx = some_fun(x)
             fx = x+a
         endfunction

         I need also error, as variable a should be passed as input argument
or defined inside some_fun body



--
Sent from: https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
kjubo kjubo
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

In reply to this post by mottelet
Dear Stephane,

thanks for tip, slint can help, but for me it looks like a manual bypass.
What I need, is that for function in level_1 (https://wiki.scilab.org/howto/global%20and%20local%20variables)
variables from level_0 are not visible.

is this possible?

BR

JK


št 7. 5. 2020 o 14:40 Stéphane Mottelet <[hidden email]> napísal(a):
Hi,

Use Scilab slint tool:

https://help.scilab.org/docs/6.1.0/en_US/slint.html

S.

Le 07/05/2020 à 14:01, kjubo a écrit :
> Dear all,
>
> I would like to ask you, how can I disable visibility of variables from
> workspace for functions.
>
> I need to be sure, that function which I convert from script file, will not
> use any variable, which is not in it input, or defined inside the function
> itself.
>
> Please see examples below.
>
> Is this possible?
>         
> Thank you
>         
> BR
>         
> JK
>
>          example 1:
>
>          a = 3
>          function fx = some_fun(x,a)
>              fx = x+a
>          endfunction
>
>          calling some_fun(5) now return 3+5, but I need to be an error.
>
>
>          example 2:
>
>          a = 3
>          function fx = some_fun(x)
>              fx = x+a
>          endfunction
>
>          I need also error, as variable a should be passed as input argument
> or defined inside some_fun body
>
>
>
> --
> Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> 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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

Hi again,

Le 07/05/2020 à 21:28, Jakub Kopac a écrit :
Dear Stephane,

thanks for tip, slint can help, but for me it looks like a manual bypass.

Sorry but you were not that clear;

> I need to be sure, that function which I convert from script file, will not
> use any variable, which is not in it input, or defined inside the function
> itself.
>
I thought you just wanted to identify functions using this sort of variable scoping before conversion (to what software ?)
What I need, is that for function in level_1 (https://wiki.scilab.org/howto/global%20and%20local%20variables)
variables from level_0 are not visible.

This is a fundamental feature of variable scope in Scilab. You may find it useful or dangerous, but this is just the way it is and cannot be disactivated...

S.



is this possible?

BR

JK


št 7. 5. 2020 o 14:40 Stéphane Mottelet <[hidden email]> napísal(a):
Hi,

Use Scilab slint tool:

https://help.scilab.org/docs/6.1.0/en_US/slint.html

S.

Le 07/05/2020 à 14:01, kjubo a écrit :
> Dear all,
>
> I would like to ask you, how can I disable visibility of variables from
> workspace for functions.
>
> I need to be sure, that function which I convert from script file, will not
> use any variable, which is not in it input, or defined inside the function
> itself.
>
> Please see examples below.
>
> Is this possible?
>         
> Thank you
>         
> BR
>         
> JK
>
>          example 1:
>
>          a = 3
>          function fx = some_fun(x,a)
>              fx = x+a
>          endfunction
>
>          calling some_fun(5) now return 3+5, but I need to be an error.
>
>
>          example 2:
>
>          a = 3
>          function fx = some_fun(x)
>              fx = x+a
>          endfunction
>
>          I need also error, as variable a should be passed as input argument
> or defined inside some_fun body
>
>
>
> --
> Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> 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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
RolandB RolandB
Reply | Threaded
Open this post in threaded view
|

Re: Variables visibility in functions

Hi,

by default, parent level variables will be visible in child level scripts.
But once you assign a value to them in the child level script, they will be
local variables unless you define something different for them.
If you afterwards just leave the child level script without taking special
measures for transferring their value back to the parent level script, the
values assigned to them will become lost.
So the only thing you have to take care of for your situation is to
initialize all variables you want to be local with some start value before
you are doing anything else with them.





--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users