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

Home » Public Forums » archive » Re: Optional parameters
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: Optional parameters [message #38182 is a reply to message #38174] Tue, 24 February 2004 21:50 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
JD Smith <jdsmith@as.arizona.edu> writes:
> I'd offer another real life example where read-write keyword variables
> can get you into trouble. When you call a function several times in a
> row, expecting the same results each time, but in actuality the
> keyword variable is defined after the first invocation, which can
> change the function's behavior:
>
> a=myfunc(test,FUNNY_VARIABLE=foo) ; foo undefined
> a=myfunc(test,FUNNY_VARIABLE=foo) ; foo defined
> a=myfunc(test,FUNNY_VARIABLE=foo) ; foo defined

Yes, I've encountered this kind of problem before as well, and it's
one of the most evil and difficult problems to solve.

That's why I define all of my functions as

pro myfunc, value=value0

;; Default value ...
if n_elements(value0) EQ 0 then value = 1 $
;; ... or requested value
else value = round(value0(0))
...
end

The "0" variable is the pristine variable that never gets changed, and
the regular variable is the one that is internal to the procedure. I
do that as a matter of habit now and it's not too labor intensive.

I do kind of wish that there would be an automatic way for IDL to peel
off a local copy of a variable for internal calculations.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: pointer and structure stuff ...
Next Topic: Re: Something similar to a "Widget_Container" ?

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

Current Time: Sat Oct 11 14:45:29 PDT 2025

Total time taken to generate the page: 0.95603 seconds