[Scilab-users] Dump the output of a function

10 messages
Open this post in threaded view
|

[Scilab-users] Dump the output of a function

 Hello,   What is the Scilab way to dump the output of a function ? The Matlab equivalent is tilde (~).   To give an example, suppose I have an existing function f such as :   function [y_1,y_2] = f(x)                 y_1 = x ^ 2;                 y_2 = x ^ 3; enfunction   Suppose I want to use this function, but I am only interested in the y_2 result, and I don’t want to assign a variable to the y_1 output. In Matlab, I would do the following way :   [~,b] = f(2)   I would only get a single output variable :   b = 8   Thank you for your feedback.   _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 Hello Christian, AFAIK there is presently no way to skip an output parameter. The more handy would be [,y2,,y4] = f(x) but unfortunately, it does not work (yet?). I did not find this feature as a wish on bugzilla. IMO it should be. It is possible to use a one-character variable name, for instance among %, #, ! or ?. --> [%,%,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); --> kb  kb  =    7.   5.   2. Even if the tilde was allowed, it is not very smart. A true blackhole would be better. Regards Samuel Le 11/01/2018 à 11:31, Soulard, Christian (GE Power) a écrit : Hello,   What is the Scilab way to dump the output of a function ? The Matlab equivalent is tilde (~).   To give an example, suppose I have an existing function f such as :   function [y_1,y_2] = f(x)                 y_1 = x ^ 2;                 y_2 = x ^ 3; enfunction   Suppose I want to use this function, but I am only interested in the y_2 result, and I don’t want to assign a variable to the y_1 output. In Matlab, I would do the following way :   [~,b] = f(2)   I would only get a single output variable :   b = 8   Thank you for your feedback.   ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 In reply to this post by Soulard, Christian (GE Power) Hello,   In Scilab 6 you can do:   function y=f(x)     y = list()     y(1) = x ^ 2;     y(2) = x ^ 3; endfunction   --> y = f(x)(2) y  =    27.   --> y = f(x)(1) y  =    9.   Regards, Rafael   From: users [mailto:[hidden email]] On Behalf Of Soulard, Christian (GE Power) Sent: Thursday, January 11, 2018 11:31 AM To: [hidden email] Subject: [Scilab-users] Dump the output of a function   Hello,   What is the Scilab way to dump the output of a function ? The Matlab equivalent is tilde (~).   To give an example, suppose I have an existing function f such as :   function [y_1,y_2] = f(x)                 y_1 = x ^ 2;                 y_2 = x ^ 3; enfunction   Suppose I want to use this function, but I am only interested in the y_2 result, and I don’t want to assign a variable to the y_1 output. In Matlab, I would do the following way :   [~,b] = f(2)   I would only get a single output variable :   b = 8   Thank you for your feedback.   _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 (sorry, x=3 line was missing)   Hello,   In Scilab 6 you can do:   function y=f(x)     y = list()     y(1) = x ^ 2;     y(2) = x ^ 3; endfunction   -->x = 3;   --> y = f(x)(2) y  =    27.   --> y = f(x)(1) y  =    9.   Regards, Rafael   From: users [[hidden email]] On Behalf Of Soulard, Christian (GE Power) Sent: Thursday, January 11, 2018 11:31 AM To: [hidden email] Subject: [Scilab-users] Dump the output of a function   Hello,   What is the Scilab way to dump the output of a function ? The Matlab equivalent is tilde (~).   To give an example, suppose I have an existing function f such as :   function [y_1,y_2] = f(x)                 y_1 = x ^ 2;                 y_2 = x ^ 3; enfunction   Suppose I want to use this function, but I am only interested in the y_2 result, and I don’t want to assign a variable to the y_1 output. In Matlab, I would do the following way :   [~,b] = f(2)   I would only get a single output variable :   b = 8   Thank you for your feedback.   _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 In reply to this post by Samuel GOUGEON Hello Christian, Samuel, My 2c, most of the modern languages supporting such a feature are using the one-character variable trick; sometimes enforced by conventions. For example, Go, Rust and Python are using `_` as in : [_,_,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); This character appears as a visual blank thus the function call is easily readable. Regards, -- Clément Le jeudi 11 janvier 2018 à 13:00 +0100, Samuel Gougeon a écrit : > Hello Christian, > > AFAIK there is presently no way to skip an output parameter. The more handy would be > [,y2,,y4] = f(x) > but unfortunately, it does not work (yet?). > I did not find this feature as a wish on bugzilla. IMO it should be. > It is possible to use a one-character variable name, for instance among %, #, ! or ?. > > --> [%,%,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); > --> kb >  kb  = > >    7.   5.   2. > > Even if the tilde was allowed, it is not very smart. A true blackhole would be better. > > Regards > Samuel > > Le 11/01/2018 à 11:31, Soulard, Christian (GE Power) a écrit : > > Hello, > >   > > What is the Scilab way to dump the output of a function ? The Matlab equivalent is tilde (~). > >   > > To give an example, suppose I have an existing function f such as : > >   > > function [y_1,y_2] = f(x) > >                 y_1 = x ^ 2; > >                 y_2 = x ^ 3; > > enfunction > >   > > Suppose I want to use this function, but I am only interested in the y_2 result, and I don’t > > want to assign a variable to the y_1 output. In Matlab, I would do the following way : > >   > > [~,b] = f(2) > >   > > I would only get a single output variable : > >   > > b = 8 > >   > > Thank you for your feedback. > >   > > > > > > _______________________________________________ > > users mailing list > > [hidden email] > > http://lists.scilab.org/mailman/listinfo/users> > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 Hello Clément, OK for your confirmation. Unfortunately, in Scilab "_" can't be used, because _() is a defined function aliasing gettext(), and Scilab needs it as is. I don't think it was a good thing to use a single character to define such an alias, but it is as is. It would be unlikely possible to rename it... Would it? Best regards Samuel ----- Mail original ----- De: "Clément David" À: [hidden email] Envoyé: Mardi 16 Janvier 2018 09:31:20 Objet: Re: [Scilab-users] Dump the output of a function Hello Christian, Samuel, My 2c, most of the modern languages supporting such a feature are using the one-character variable trick; sometimes enforced by conventions. For example, Go, Rust and Python are using `_` as in : [_,_,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); This character appears as a visual blank thus the function call is easily readable. Regards, -- Clément _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 Hello all, I might say something really stupid, but can't we define a special variable like %eps, %i, etc to act as a black hole ? Something like %null (like piping to /dev/null or a null pointer) or a better name (%blackhole, %lostforever, %byebye, ;-) ). The idea being that no memory is allocated when someone try to affect some value to it: [%null,%null,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); Antoine Le 16/01/2018 à 14:12, [hidden email] a écrit : > Hello Clément, > > OK for your confirmation. Unfortunately, in Scilab "_" can't be used, because _() is a defined function aliasing gettext(), and Scilab needs it as is. > > I don't think it was a good thing to use a single character to define such an alias, but it is as is. > It would be unlikely possible to rename it... Would it? > > Best regards > Samuel > > ----- Mail original ----- > De: "Clément David" > À: [hidden email] > Envoyé: Mardi 16 Janvier 2018 09:31:20 > Objet: Re: [Scilab-users] Dump the output of a function > > Hello Christian, Samuel, > > My 2c, most of the modern languages supporting such a feature are using the one-character variable > trick; sometimes enforced by conventions. For example, Go, Rust and Python are using `_` as in : > > [_,_,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); > > This character appears as a visual blank thus the function call is easily readable. > > Regards, > > -- > Clément > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users> _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Dump the output of a function

 Le 17/01/2018 à 18:16, antoine monmayrant a écrit : Hello all, I might say something really stupid, but can't we define a special variable like %eps, %i, etc to act as a black hole ? Something like %null (like piping to /dev/null or a null pointer) or a better name (%blackhole, %lostforever, %byebye, ;-) ). The idea being that no memory is allocated when someone try to affect some value to it: [%null,%null,kb] = intersect(grand(1,10,"uin",0,9), grand(1,10,"uin",0,9)); A true black hole has even no name :) Otherwise, the shorter the better, and "_" would be nice after deprecating _() (*). Anyway, IMO this black hole feature has a very low priority compared to some other ones, like some big regressions (bug 13808 = 14881, sparse() with repeated indices, etc etc) or some very and longly expected ones like a varprot()... Samuel (*) it could be renamed something like _tr() (standing for translate). The number of occurrences of _() to be converted in the Scilab native code is very important, but the conversion might be automated (since the gettext() scanner has a reliable detection criterium, and only .sci, .sce, .tst and .dia.ref files are targeted). gettext() and _() are almost unused in external modules, because the gettext domain feature has never worked (or please just give us a working example... Never seen a single one). _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users