comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Procedures with variable/dynamic argument list??
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Procedures with variable/dynamic argument list?? [message #73084 is a reply to message #73077] Fri, 22 October 2010 07:26 Go to previous messageGo to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Oct 22, 9:56 am, "Kenneth P. Bowman" <k-bow...@null.edu> wrote:
> In article
> < d5d024b5-fb3e-438e-9277-c4dc032c3...@n24g2000prj.googlegroup s.com >,
>
>  SonicKenking <ywa...@gmail.com> wrote:
>> Is it possible in IDL to code a procedure using variable/dynamic
>> argument list?? i.e. the number of arguments is arbitrary and the
>> procedure is able to accept them all with some argument array?
>
>> Similar to the "va_list" in C or "*args" in Python.
>
>> The Print command in IDL is a good example too for accepting arbitrary
>> number of arguments and print them all. Unfortunately, the Print
>> command is not written in IDL, hence no sneak peek of the source code
>> ~~
>
> IDL procedures and functions are flexible about how many
> arguments you provide, as long as you don't pass too many.
>
> You do have to provide at least as many dummy arguments
> in the procedure definition as you intend to use.  That is
>
>    PRO VAR_ARGS, a1, a2, a3, a4
>
> can be called as
>
>    VAR_ARGS, x, y
>
> It is up to the procedure to know what to do in that
> case.  (See the N_PARAMS function.)
>
> As far as I know, there is no direct mechanism for
> handling an arbitrary number of arguments other than
> making a list in the procedure/function definition.
>
> Ken

It comes out pretty ugly indeed... here my "pritn" function
that I use to work around my bad spelling (!)
I guess I didn't know about n_params() when I wrote that.


Ciao,
Paolo

PRO pritn,a1,a2,a3,_extra=_extra

IF exist(a3) THEN print,a1,a2,a3,_extra=_extra ELSE $
IF exist(a2) THEN print,a1,a2,_extra=_extra ELSE $
IF exist(a1) THEN print,a1,_extra=_extra

END

;from solarsoft
function exist,var

return,n_elements(var) ne 0

end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDLdoc 3.3 released
Next Topic: Re: the "real" screen size

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:26:33 PDT 2025

Total time taken to generate the page: 0.00193 seconds