cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
0 Kudos

User Defined Function Return Multiple Outputs

Hello, 

       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 . 

5 Comments
brady_brady
Staff

You 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);
uday_guntupalli
Level VIII

@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 

Jeff_Perkinson
Community Manager
Status changed to: Already Offered

As 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"]);

@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).

 

Ryan_Gilmore
Community Manager
Status changed to: Delivered