Re: [Scilab-users] Arguments of functions in Scilab

2017-03-05 Thread Samuel Gougeon

Le 05/03/2017 à 16:06, Samuel Gougeon a écrit :


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.


Hmm, actually, such a change would prevent handy calls like
--> help
Having to enter
--> help()
would be definitely less handy.

Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Arguments of functions in Scilab

2017-03-05 Thread Samuel Gougeon

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

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

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] Arguments of functions in Scilab

2017-03-04 Thread Pierre Vuillemin

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?
 * 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
    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?


Best regards,

Pierre

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users