[Scilab-users] Arguments of functions in Scilab

Samuel Gougeon sgougeon at free.fr
Sun Mar 5 16:06:03 CET 2017


Hello Pierre,

I am answering in the thread:

Le 04/03/2017 à 12:27, Pierre Vuillemin a écrit :
>
> Hi all,
>
> I'm a bit confused by functions in Scilab and specifically the way 
> they handle their arguments. For instance, in the following code
>
> deff('g(x)','disp(x)');
> g; // produces an error saying x is not defined
> x = 1;
> g; // call the function g and displays x...
>
> leads to two questions,
>
>   * the function g is called each time, shouldn't it be only displayed?
>

I agree with you: since g is written without (empty) (), considering it 
as the function handle instead of a function call would be more 
consistent, as when we write: d = g  // to set an alias of g.


>   * the second call 'works' and display x, even if the argument of the
>     function has not been provided.  I've read the page concerning
>     scoping of variables
>     <https://wiki.scilab.org/howto/global%20and%20local%20variables>
>     in Scilab, but shouldn't it says that the function was expecting 1
>     argument?
>
> This feels a bit unsafe to me, I'm wondering what is the reason behind 
> this choice?
>

The Scilab kernel protests only when /more /than the maximal number of 
expected input or output arguments are provided, /never less/:
--> g(2,4)
Wrong number of input arguments.
--> b = g(2)
Wrong number of output arguments.

This means that, /by default, all input and output arguments are 
optional/. I think this is an handy assumption. It lets the developper 
managing arguments checking and setting /addition/ constraints on 
arguments in a single function definition

Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170305/c6d7c1b7/attachment.htm>


More information about the users mailing list