[Scilab-users] Nested function definition
Izabela Wójcik-Grząba
iwoj at il.pw.edu.pl
Wed Apr 10 17:31:10 CEST 2019
Ok, sorry. It's my mistake connected with using math terms not properly.
Now I understand that nested function is more general term in Scilab
help. The help example is similar to mine and this is the whole
misunderstanding.
I appreciate your comprehensive explanation.
Now I am happy because the notation of my (mathematical) functions
become simpler.
Kind regards,
Iza
W dniu 10.04.2019 17:10, Samuel Gougeon napisał(a):
> Izabela,
>
> I have not clearly understood why you are speaking about "nested
> functions" in your example.
> A nested function is a function that is _defined_ in another one.
>
> About the example in the function help page:
> It is right, but with Scilab 6, it looks a bit outdated to me.
> Indeed, let's consider the following example:
>
> // Content of the File myTest.sci
> function myTest()
> disp("myTest() is running")
> myNextFun()
> endfunction
> function myNextFun()
> disp("myNextFun() is running")
> endfunction
> // End of myTest.sci file
>
> When building a library (say "myLib"), this file is compiled, and
>
> * With Scilab 5 : both functions myTest() and myNextFun() are
> registered in the library, and so ARE PUBLIC: Both can be called from
> anywhere, noticeably from the top-level, the console.
> The only way to make myNextFun() a private function known only by
> myTest() is to define it IN myTest(), as a nested function.
>
> * With Scilab 6: only myTest() is registered in myLib library, so is
> public, and can be called from anywhere. In the opposite, myNextFun()
>
> * is NOT registered in the library
> * so, is unknown from the console,
>
> * is shared and can be called only by other functions defined in the
> same file.
>
> This is a more powerful implementation for the functions privacy,
> because then
> * a private function (say myNextFun()) does no longer need to be
> recompiled each time that myTest() is called.
>
> * IMO, this makes the code clearer
>
> This change in Scilab 6 could be documented in the --> help function
> page, in order to discourage true nested function. By the way, the
> example in the help misses being indented.
>
> However, out of libraries, nested functions can still be used in
> scripts.sce or in files.sci that are just exec()uted, for the same
> purpose: keeping nested functions private.
>
> HTH
> Regards
> Samuel
>
> Le 10/04/2019 à 16:04, Izabela Wójcik-Grząba a écrit :
>
>> Ok, so why nested function in help is so complicated:
>>
>> //nested functions definition
>> function y=foo(x)
>> a=sin(x)
>> function y=sq(x), y=x^2,endfunction
>> y=sq(a)+1
>> endfunction
>>
>> foo(%pi/3)
>>
>> Couldn't it be formulated like below:
>>
>> function y1=foo1(x)
>> a=sin(x);
>> y1=a^2+1;
>> endfunction
>>
>> foo1(%pi/3)
>>
>> That's why I had problems with my functions and couldn't understand
>> why it has to be so complicated.
>>
>> Thank you once more.
>>
>> Iza
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
More information about the users
mailing list