IDL wish list: _EXTRA for positional parameters
posted Tue 10 Nov 2015 by Michael Galloy under Feature request, IDLIDL already contains syntax for passing arbitrary (and perhaps unknown beforehand) keywords to a routine using the _EXTRA
and _REF_EXTRA
keywords, depending on whether you are passing a variable back to the caller through the keyword. For example, you can do something like this:
pro my_wrapper_routine, _extra=e
my_routine, _extra=e
end
Now, MY_WRAPPER_ROUTINE
passes all the keywords that MY_ROUTINE
accepts along to it (ignoring any others, use _STRICT_EXTRA
on the MY_ROUTINE
call to generate an error if an unknown keyword is passed in).
It would be useful to have a similar mechanism for positional parameters, making it possible to write routines in IDL which accept an arbitrary number of keywords or pass along parameters to another routine. For example, passing all parameters after the first two to another routine and printing the first “extra” parameter with the new library routine GET_PARAM
:
pro my_wrapper_routine, a, b, _extra
my_routine, _extra
print, get_param(_extra, 0)
end
What exactly would the _extra
variable be? I’m not sure. Maybe it isn’t even needed in the GET_PARAM
call, but it certainly is needed in the MY_ROUTINE
call. Python handles this through tuples and the special *
notation, maybe IDL can use structures and a bit of new notation?
But I would certainly like to get rid of code like the following:
case n_params() of
0: _sql_query = ''
1: _sql_query = sql_query
2: _sql_query = string(arg1, format='(%"' + sql_query + '")')
3: _sql_query = string(arg1, arg2, format='(%"' + sql_query + '")')
4: _sql_query = string(arg1, arg2, arg3, format='(%"' + sql_query + '")')