[Scilab-users] On parameters passing by name in scilab functions

Tim Wescott tim at wescottdesign.com
Mon Feb 27 19:49:59 CET 2017


You misread my comments.  Tim _likes_ named parameters.  If Tim were on
the C++ standards committee (which is as likely as pigs flying, BTW)
Tim would agitate that named parameters be adopted into that language.
 Scilab, Verilog, and (I think) VHDL have it, and particularly in a
language that allows for optional parameters, I feel that when you have
to have function calls with more than a few parameters it vastly aids
code readability.

On Mon, 2017-02-27 at 19:36 +0100, Samuel Gougeon wrote:
> Hello Adelson,
> 
> Le 27/02/2017 à 15:46, Adelson Oliveira a écrit :
> > Hi,
> > 
> > Let's take fft as an example.
> > 
> > In scilab 5 one could call fft specifying parameters like dim and
> > incr by name,
> > 
> > fft(A,-1,dim=100,incr=1)
>  Here names are simply ignored. There would be a true call by names
> if the order would not matter, while it does:
> -->Fp2 = fft(A,-1,incr=1,dim=100);
>                                !--error 999 
> fftw: Wrong values for input argument #3: Elements must be greater
> than 1.
> 
> I guess that this is because fft() is a built-in, not a "macro".
> But even for functions written in Scilab language (aka macros),
> passing named parameters is strongly discouraged:
> this sets a formal link between the calling level and the inner
> called one. Then, any change of the parameters names in the function
> definition breaks such calls.
> the definition of most (say 99%) scilab functions test input
> parameters against their position rather than their name. It is not
> robust, but so it is. So (provided that fft() would be a macro) when
> calling fft(1,-1,incr=1), incr is detected at the third position
> while in the definition it is listed in the 4th one. Really efficient
> to get a mess ;)
> function test(a, b)
>     mprintf("RHS=%d, exists(a)=%d  exists(b)=%d\n", argn(2),
> exists("a","l"), exists("b","l"))
> endfunction
> -->test(b=1)
> RHS=1, exists(a)=0  exists(b)=1
>  
> -->test(b=1,a=2)
> RHS=2, exists(a)=1  exists(b)=1
> So, Tim is right. Calls with named parameters make the code fragile,
> or make somewhat harder to code the analysis of input arguments in a
> robust way. This coding way still increases functions overheads, that
> make them slower.
> Samuel
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432






More information about the users mailing list