Reputation: 156
Is it possible to determine the number of arguments of a function in Scilab ?
let's say I have a function as follows :
function T = test(t,x)
T = t*x
endfunction
In this case I should get 2 as output. To be more specific, my goal here is to know the number of arguments but uniquely using the function's name.
function N = NumberArgument(F)
// F is a function
N = ....
endfunction
And so I want to have
a = NumberArgument(test)
a = 2
Thank you for your answer
Upvotes: 2
Views: 247
Reputation: 2955
Yes, using argn
you can determine the number of input & output arguments
function T = test(t,x)
[lhs,rhs]=argn(0);
disp(rhs);
T = t*x;
endfunction
Using macrovar
you can determine the number of arguments from outside the function
function N = NumberArgument(F)
// F is a function
all_vars = macrovar(F);
in_vars = all_vars(1);
N = size(in_vars, 1);
endfunction
disp(NumberArgument(test))
Upvotes: 1
Reputation: 8359
Short:
I think it's not possible.
Long:
You want to get the type signature of a function.
After a little bit of research I find out that user defined functions and some built-in function (the ones coded in scilab) have the same type:
-->deff('[r] = test(a, b)', 'r=a*b');
-->type(test)
ans =
13.
-->type(plot)
ans =
13.
I think you can't have more information about a function than is type.
Now, let say you want the signature of plot.
And as you can see here there are multiple signature (note that plot()
without arguments is not documented).
Almost all scilab function use argn and the signature possibility with this is illimited...
Upvotes: 0