Multiple Functions in a sci file

classic Classic list List threaded Threaded
6 messages Options
Tan Chin Luh-2 Tan Chin Luh-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multiple Functions in a sci file

Hi,

I am trying to troubleshoot the issue on the guibuilder in Scilab 6 windows platform as reported by :

https://atoms.scilab.org/toolboxes/guibuilder/3.1#comment2713

-----------
I used guibuilder in 5.5.2 and was able to create a gui, open an existing gui.  I just 
installed it for 6.0 and the guibuilder launches, but am unable to create anything, i 
get the error "Undefined variable: draw_uicontrol5" for anything that I click on
to 
create. Or even to open an existing GUI.
-----------

I tried to reproduce the error in a simpler manner: 

1. Write a simple sci file with 2 functions in it.

function y = test1(x)
    y = x+1;
endfunction

function y = testa(x)
    y = x+2;
endfunction

2. Put the file in a folder and use genlib to generate the lib

3. Load the library and call "test1(1)" and "testa(1)"

In Scilab 5.5.2, both functions are callable, but in Scilab 6, only test1 is, and calling testa will either return error "undefined variable" or just crashed the Scilab.

Is this meant to behave this way under "new parser and new core"?

I try to screen through what's news in Scilab 6 and bugzilla, and the similar but not exact issue found is : http://bugzilla.scilab.org/show_bug.cgi?id=14525

I try to avoid breaking out all the functions to separate files as it will be tones of files in the folder then.

Thanks.

Regards,
Chin Luh


To reproduce the case, following lines works for Scilab 5.5.2 but not Scilab 6

////

lib_path = TMPDIR + "/test1";
mkdir(lib_path);
file_path = lib_path + "/test1.sci";
fd = mopen(file_path, 'wt');
mputl(["function y = test1(x)"
"y = x+1;"
"endfunction"
""
"function y = testa(x)"
"y = x+2;"
"endfunction"], fd);
mclose(fd);

genlib('libfoo', lib_path);

lib(lib_path);

test1(1)

testa(1)

///


_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Private functions in a .sci file <= Re: Multiple Functions in a sci file

Hi,

Le 16/02/2017 à 06:04, Tan Chin Luh a écrit :

Hi,

I am trying to troubleshoot the issue on the guibuilder in Scilab 6 windows platform as reported by :

https://atoms.scilab.org/toolboxes/guibuilder/3.1#comment2713

-----------
I used guibuilder in 5.5.2 and was able to create a gui, open an existing gui.  I just 
installed it for 6.0 and the guibuilder launches, but am unable to create anything, i 
get the error "Undefined variable: draw_uicontrol5" for anything that I click on
to 
create. Or even to open an existing GUI.
-----------

I tried to reproduce the error in a simpler manner: 

1. Write a simple sci file with 2 functions in it.

function y = test1(x)
    y = x+1;
endfunction

function y = testa(x)
    y = x+2;
endfunction

2. Put the file in a folder and use genlib to generate the lib

3. Load the library and call "test1(1)" and "testa(1)"

In Scilab 5.5.2, both functions are callable, but in Scilab 6, only test1 is, and calling testa will either return error "undefined variable" or just crashed the Scilab.

Is this meant to behave this way under "new parser and new core"?


AFAIK : yes.
Now, only the first function defined in the file (or the one whose name matches the file name? To be tested) is public. All other ones are private (their domain is unclear: (likely) only the main function? or the whole library it belongs to? To be tested and documented).
One of the (nice) consequences is that, now none of the private functions appears in the whos list of defined functions. They were formerly rather spamming the list.

I try to screen through what's news in Scilab 6 and bugzilla, and the similar but not exact issue found is : http://bugzilla.scilab.org/show_bug.cgi?id=14525


You are right, i don't think it is already correctly documented. There were some discussions on users@ about this change since mid-2015, but since Scilab 5.5.2, the genlib() help page was improved for Scilab 5, without being updated for Scilab 6.

I try to avoid breaking out all the functions to separate files as it will be tones of files in the folder then.


I am afraid that, if each of your functions is -- say -- a callback, it must be public, and then now it requires to be defined in a separate .sci file.

Regards
Samuel


_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Tan Chin Luh-2 Tan Chin Luh-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Private functions in a .sci file <= Re: Multiple Functions in a sci file

Hi Samuel,

Thanks for your answers.

best regards,
Chin Luh

On 22/2/2017 5:22 AM, Samuel Gougeon wrote:
Hi,

Le 16/02/2017 à 06:04, Tan Chin Luh a écrit :

Hi,

I am trying to troubleshoot the issue on the guibuilder in Scilab 6 windows platform as reported by :

https://atoms.scilab.org/toolboxes/guibuilder/3.1#comment2713

-----------
I used guibuilder in 5.5.2 and was able to create a gui, open an existing gui.  I just 
installed it for 6.0 and the guibuilder launches, but am unable to create anything, i 
get the error "Undefined variable: draw_uicontrol5" for anything that I click on
to 
create. Or even to open an existing GUI.
-----------

I tried to reproduce the error in a simpler manner: 

1. Write a simple sci file with 2 functions in it.

function y = test1(x)
    y = x+1;
endfunction

function y = testa(x)
    y = x+2;
endfunction

2. Put the file in a folder and use genlib to generate the lib

3. Load the library and call "test1(1)" and "testa(1)"

In Scilab 5.5.2, both functions are callable, but in Scilab 6, only test1 is, and calling testa will either return error "undefined variable" or just crashed the Scilab.

Is this meant to behave this way under "new parser and new core"?


AFAIK : yes.
Now, only the first function defined in the file (or the one whose name matches the file name? To be tested) is public. All other ones are private (their domain is unclear: (likely) only the main function? or the whole library it belongs to? To be tested and documented).
One of the (nice) consequences is that, now none of the private functions appears in the whos list of defined functions. They were formerly rather spamming the list.

I try to screen through what's news in Scilab 6 and bugzilla, and the similar but not exact issue found is : http://bugzilla.scilab.org/show_bug.cgi?id=14525


You are right, i don't think it is already correctly documented. There were some discussions on users@ about this change since mid-2015, but since Scilab 5.5.2, the genlib() help page was improved for Scilab 5, without being updated for Scilab 6.

I try to avoid breaking out all the functions to separate files as it will be tones of files in the folder then.


I am afraid that, if each of your functions is -- say -- a callback, it must be public, and then now it requires to be defined in a separate .sci file.

Regards
Samuel



_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev



_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Antoine ELIAS-2 Antoine ELIAS-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Private functions in a .sci file <= Re: Multiple Functions in a sci file

Hello,

After some tests, it seems that Scilab 5 loads in local context "sub
functions" only when you call the main function.

with your sample, test1 and testa in the same test1.sci file
genlib -> load -> testa -> KO
                -> test1 -> testa -> OK

In Scilab 6, we load "sub functions" as nested functions of the main
function.
So they can be called in main function but after the call, they are
"cleared".

It is a regression, can you open a bug with a link to this thread ?

Regards,
Antoine

Le 2017-02-22 02:50, Tan Chin Luh a écrit :

> Hi Samuel,
>
>  Thanks for your answers.
>
>  best regards,
>  Chin Luh
>
>  On 22/2/2017 5:22 AM, Samuel Gougeon wrote:
>
>> Hi,
>>
>> Le 16/02/2017 à 06:04, Tan Chin Luh a écrit :
>>
>>> Hi,
>>>
>>> I am trying to troubleshoot the issue on the guibuilder in Scilab
>>> 6 windows platform as reported by :
>>>
>>> https://atoms.scilab.org/toolboxes/guibuilder/3.1#comment2713 [1]
>>>
>>> -----------
>>>
>>> I used guibuilder in 5.5.2 and was able to create a gui, open an
>>> existing gui. I just
>>> installed it for 6.0 and the guibuilder launches, but am unable to
>>> create anything, i
>>> get the error "Undefined variable: draw_uicontrol5" for anything
>>> that I click on
>>> to
>>> create. Or even to open an existing GUI.
>>> -----------
>>>
>>> I tried to reproduce the error in a simpler manner:
>>>
>>> 1. Write a simple sci file with 2 functions in it.
>>>
>>> function y = test1(x)
>>> y = x+1;
>>> endfunction
>>>
>>> function y = testa(x)
>>> y = x+2;
>>> endfunction
>>>
>>> 2. Put the file in a folder and use genlib to generate the lib
>>>
>>> 3. Load the library and call "test1(1)" and "testa(1)"
>>>
>>> In Scilab 5.5.2, both functions are callable, but in Scilab 6,
>>> only test1 is, and calling testa will either return error
>>> "undefined variable" or just crashed the Scilab.
>>>
>>> Is this meant to behave this way under "new parser and new core"?
>>
>> AFAIK : yes.
>> Now, only the first function defined in the file (or the one whose
>> name matches the file name? To be tested) is public. All other ones
>> are private (their domain is unclear: (likely) only the main
>> function? or the whole library it belongs to? To be tested and
>> documented).
>> One of the (nice) consequences is that, now none of the private
>> functions appears in the whos list of defined functions. They were
>> formerly rather spamming the list.
>>
>>> I try to screen through what's news in Scilab 6 and bugzilla, and
>>> the similar but not exact issue found is :
>>> http://bugzilla.scilab.org/show_bug.cgi?id=14525 [2]
>>
>> You are right, i don't think it is already correctly documented.
>> There were some discussions on users@ about this change since
>> mid-2015, but since Scilab 5.5.2, the genlib() help page was
>> improved for Scilab 5, without being updated for Scilab 6.
>>
>>> I try to avoid breaking out all the functions to separate files as
>>> it will be tones of files in the folder then.
>>
>> I am afraid that, if each of your functions is -- say -- a
>> callback, it must be public, and then now it requires to be defined
>> in a separate .sci file.
>>
>> Regards
>> Samuel
>>
>> _______________________________________________
>> dev mailing list
>> [hidden email]
>> http://lists.scilab.org/mailman/listinfo/dev [3]
>
>
>
> Links:
> ------
> [1] https://atoms.scilab.org/toolboxes/guibuilder/3.1#comment2713
> [2] http://bugzilla.scilab.org/show_bug.cgi?id=14525
> [3] http://lists.scilab.org/mailman/listinfo/dev
>
> _______________________________________________
> dev mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/dev
_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Private functions in a .sci file <= Re: Multiple Functions in a sci file

Hello Antoine,

I am answering in the thread:

Le 22/02/2017 à 14:28, [hidden email] a écrit :
Hello,

After some tests, it seems that Scilab 5 loads in local context "sub functions" only when you call the main function.

yes, the first time that the registered function is used.

with your sample, test1 and testa in the same test1.sci file
genlib -> load -> testa -> KO
               -> test1 -> testa -> OK
and then, next calls
-> testa -> OK


In Scilab 6, we load "sub functions" as nested functions of the main function.
So they can be called in main function but after the call, they are "cleared".

It is a regression,

Really?! I am very surprised by this assertion. Some (may be many) former native Scilab .sci files have been split to work in this new way -- for instance ged.sci embedded many subfunctions that have been transfered in as many separated files (and moved to the TCL module...). And AFAIRemember, this feature was already discussed in 2015 on users@ or devs@. So, i believed, and still believe that this change is intentional.
By the way, this new behavior has some advantages. Without it, making private functions compels to define them a) inside the calling one, and b) at its beginning. This was not very smart programming.
The only way to avoid explicitly defining them at the beginning was to exec them (still at the beginning).
I never run any benchmarks to compare timing of exec()uting an external definition file at run time:

function test()

  exec("mysubfunction.sci")
endfunction

versus compiling an embedded function/endfunction as well at run time:

function test()

     function mysubfunction(..)
         // Its code
    endfunction
endfunction

A priori, i would say that using an external file laying on the disk is slower than compiling things in RAM.
So, imo, this change was not really expected, but it leads to a smarter programming, and likely processes subfunctions in a faster way.
So, why do you say that it is a regression ?

BR
Samuel


_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Tan Chin Luh-2 Tan Chin Luh-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Private functions in a .sci file <= Re: Multiple Functions in a sci file

Hi,

i am sorry to had overlooked this thread. So is it confirmed to be a regression ? as we have 2 opinions here. :)

Thanks.

Regards,
Chin Luh

On 23/2/2017 7:50 AM, Samuel Gougeon wrote:
Hello Antoine,

I am answering in the thread:

Le 22/02/2017 à 14:28, [hidden email] a écrit :
Hello,

After some tests, it seems that Scilab 5 loads in local context "sub functions" only when you call the main function.

yes, the first time that the registered function is used.

with your sample, test1 and testa in the same test1.sci file
genlib -> load -> testa -> KO
               -> test1 -> testa -> OK
and then, next calls
-> testa -> OK


In Scilab 6, we load "sub functions" as nested functions of the main function.
So they can be called in main function but after the call, they are "cleared".

It is a regression,

Really?! I am very surprised by this assertion. Some (may be many) former native Scilab .sci files have been split to work in this new way -- for instance ged.sci embedded many subfunctions that have been transfered in as many separated files (and moved to the TCL module...). And AFAIRemember, this feature was already discussed in 2015 on users@ or devs@. So, i believed, and still believe that this change is intentional.
By the way, this new behavior has some advantages. Without it, making private functions compels to define them a) inside the calling one, and b) at its beginning. This was not very smart programming.
The only way to avoid explicitly defining them at the beginning was to exec them (still at the beginning).
I never run any benchmarks to compare timing of exec()uting an external definition file at run time:

function test()

  exec("mysubfunction.sci")
endfunction

versus compiling an embedded function/endfunction as well at run time:

function test()

     function mysubfunction(..)
         // Its code
    endfunction
endfunction

A priori, i would say that using an external file laying on the disk is slower than compiling things in RAM.
So, imo, this change was not really expected, but it leads to a smarter programming, and likely processes subfunctions in a faster way.
So, why do you say that it is a regression ?

BR
Samuel



_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev



_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Loading...