User Defined Function Return Multiple OutputsHello,
Would like to open a request for the ability to allow a user defined function to return more than one argument as output . If I am not wrong , the current definition of a user defined function in JSL , looks something like this :
FunctionName = function({args_list},{localvars_List},
// Logic
// Return
Return(OutputVar); // where OutputVar can be list or data table or matrix
); I think it would be highly beneficial to allow retrieve multiple arguments easily when calling the function. Please kindly provide an example should such a feature already exist .
Automation and ScriptingRe: User Defined Function Return Multiple Outputs - Status changed to: DeliveredRe: User Defined Function Return Multiple Outputs@uday_guntupalli, Starting with JMP 14, you will be able to use the Return() function to return multiple values (without the need for EvalList(List())). S1298458
I'm sure @Jeff_Perkinson will come by soon (edit: he already did) and mark this as resolved (as only admins can change the status).
Re: User Defined Function Return Multiple Outputs - Status changed to: Already OfferedAs discussed above, JSL already supports this by returning a list.
Another option is returning an associative array. This way function callers don't have to remember the order of the results.
mathOps = function({a,b},
{default local},
associative array({"sum", "difference", "product", "quotient"}, eval list({a+b, a-b, a*b, a/b}))
);
results = mathOps(10,5);
show(results["sum"]);Re: User Defined Function Return Multiple Outputs@brady_brady,
Thanks a lot for the example. Would you be kind enough to mark the idea as "feature exists" as I dont see an option to do it
Re: User Defined Function Return Multiple OutputsYou can do this by returning a list of the return values. In most cases, you will want to evaluate the list before returning it, using Eval List ( ).
For example, the function MathOps shown below takes as input two numbers and returns their sum, difference, product and quotient.
Cheers,
Brady
mathOps = function({a,b},
{default local},
evallist({a+b, a-b, a*b, a/b})
);
{s, d, p, q} = mathOps(10,5);