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 #73077 is a reply to message #73075] Fri, 22 October 2010 08:14 Go to previous messageGo to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Oct 22, 8:26 am, Paolo <pgri...@gmail.com> wrote:
>
> 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

Hi all,

You might look at SCOPE_VARFETCH. You could dynamically construct the
argument name, and then pass the string to SCOPE_VARFETCH to retrieve
the value. Something like:

PRO pritn,a1,a2,a3,_extra=_extra
for i=1,n_params() do print, SCOPE_VARFETCH('a'+strtrim(i,
2)),_extra=_extra
end

This only helps in cases where you can break up the arguments and do a
call with each one separately.

Paolo, if I could suggest a tweak, you could use a CASE statement
instead:

case n_params() of
1: print,a1,_extra=_extra
2: print,a1,a2,_extra=_extra
3: print,a1,a2,a3,_extra=_extra
else: message,'Incorrect number of arguments'
endcase

This avoids all of those nasty if/else blocks.

-Chris
ITTVIS
[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:06:04 PDT 2025

Total time taken to generate the page: 0.00475 seconds