Post Reply 
Calling a function with an arbitrary number of arguments
05-04-2019, 03:37 PM (This post was last modified: 05-05-2019 04:02 AM by Han.)
Post: #4
RE: Calling a function with an arbitrary number of arguments
Here is a short (CAS) program that takes a variable number of inputs. In this case, we expect 2 inputs but the program handles cases where more (or fewer) than 2 inputs are provided (by returning an error message). Here, the input is the variable 'args' which is (conceptually speaking) a list of values, which are then turned into a vector of values called 'argv' by encapsulating the list of values in square brackets. Non-CAS programs cannot handle variable inputs; but one way to get around this is to create a "wrapper" CAS program that handles the input and then passes it to your non-CAS program(s).

Code:
#cas
jacob(args):=
begin
local argv, argc, mat, f, var, fn, j, k,  gr, vd;
argv:=[args];
argc:=size(argv);
IF argc !=2 THEN
     return "Input:[f1(x1,...,xn),...,fm(x1,...,xn)], [x1,...,xn]"; 
ELSE
     return transpose(diff(argv[1],argv[2]));
END;
end;
#end

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Calling a function with an arbitrary number of arguments - Han - 05-04-2019 03:37 PM



User(s) browsing this thread: 1 Guest(s)