<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hello Pierre,<br>
<br>
I am answering in the thread:<br>
<br>
Le 04/03/2017 à 12:27, Pierre Vuillemin a écrit :<br>
</div>
<blockquote
cite="mid:1971c8b0-6ccc-fd90-f630-e8301e13a52b@pierre-vuillemin.fr"
type="cite">
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<p>Hi all,</p>
<p>I'm a bit confused by functions in Scilab and specifically the
way they handle their arguments. For instance, in the following
code</p>
<p><font size="-1">deff('g(x)','disp(x)');</font><br>
<font size="-1">g; // produces an error saying x is not defined</font><br>
<font size="-1">x = 1;</font><br>
<font size="-1">g; // call the function g and displays x...</font><br>
</p>
<p>leads to two questions,<br>
</p>
<ul>
<li>the function g is called each time, shouldn't it be only
displayed?</li>
</ul>
</blockquote>
<br>
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.<br>
<br>
<br>
<blockquote
cite="mid:1971c8b0-6ccc-fd90-f630-e8301e13a52b@pierre-vuillemin.fr"
type="cite">
<ul>
<li>the second call 'works' and display x, even if the argument
of the function has not been provided. I've read the page
concerning <a moz-do-not-send="true"
href="https://wiki.scilab.org/howto/global%20and%20local%20variables">scoping
of variables</a> in Scilab, but shouldn't it says that the
function was expecting 1 argument?<br>
</li>
</ul>
<p>This feels a bit unsafe to me, I'm wondering what is the reason
behind this choice?<br>
</p>
</blockquote>
<br>
The Scilab kernel protests only when <i>more </i>than the maximal
number of expected input or output arguments are provided, <i>never
less</i>:<br>
<tt>--> g(2,4)</tt><tt><br>
</tt><tt>Wrong number of input arguments.</tt><tt><br>
</tt><tt>--> b = g(2)</tt><tt><br>
</tt><tt>Wrong number of output arguments.</tt><tt><br>
</tt><br>
This means that, <i>by default, all input and output arguments are
optional</i>. I think this is an handy assumption. It lets the
developper managing arguments checking and setting <i>addition</i>
constraints on arguments in a single function definition<br>
<br>
Samuel<br>
<br>
</body>
</html>