Optional arguments in functions<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />HI folks,
I just started using JMP after spending almost 10 years using IDL,
therefore transistioning from expert to beginner.
I am mostly in the process of learning the scripting language right now.
Hopefully you'll pardon me for the occasional silly question
So I'll start with a simple question:
What is the best way to use optional arguments in functions?
When I run scripts they do complain if I use less then the number
of arguments specified in the argument list of the function.
One could conceivably use associative arrays as input instead,
and have optional keys in there, but that requires the user to
create one every time the function is called, which seems a bit
cumbersome....
Thanks!
Paolo Grigis
ABB Switzerland
Optional arguments in functionsHi Paolo
You will probably get some more helpful responses if you can give some examples of the type of functions that you are using.
Typically functions have required arguments that need to be parsed in a specific order, but there are additional optional arguments, often specified by keywords, that can be specified in any position and omitted if not required.
As far as I am aware it is not possible to parse the arguments as a list, they have to be specified indivdually, except of course where the argument item is itself a list. However, there is a JSL function called FUNCTION that allows you to create user-defined functions. I often use this capability to "wrap" an existing JSL function so that I have more control of the input arguments.
Regards,
Dave
Optional arguments in functionsPaulo
If you create a user-defined function then you have the option of specifying default values for arguments. If defaults are specified then the arguments become optional.
So in the example below the 3rd argument is optional and defaults to missing (indicated by a dot in JSL)
My Function = Function( {a,b,c=.}, {Default Local},
show(IsMissing(c));
show(a,b,c)
);
My Function( 1, 2 )
Regards,
Dave