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

Home » Public Forums » archive » Re: Keyword precedence
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: Keyword precedence [message #21517 is a reply to message #21513] Mon, 28 August 2000 00:00 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Mark Hadfield" <m.hadfield@niwa.cri.nz> writes:

> It's interesting that David Fanning and Martin Shultz have both recommended
> the following idiom for establishing overridable defaults
>
> pro my_plot, COLOR=color, _EXTRA=extra
> if n_elements(color) eq 0 then color = 12
> plot, COLOR=12, _EXTRA=extra
**** Ooops ^^ ****
> end
>
> This has the effect, unintended and normally irrelevant, that if the
> following call is made with the COLOR keyword set to an undefined variable
>
> my_plot, COLOR=color
>
> then this variable is set to 12 on output. It isn't too hard to imagine a
> situation (successive calls to different routines with different default
> colours) where this will bite an unwary programmer, though in several years
> of using this idiom I have seldom thought about this side-effect and have
> very seldom been bitten.

I have had a difficult time keeping up with this thread. Whew! I
often do my keyword passing with the following draconian but safe
technique.

pro my_plot, COLOR=color0, _EXTRA=extra
if n_elements(color0) eq 0 then color = 12 $
else color = floor(color0(0))
plot, COLOR=color, _EXTRA=extra
end

COLOR0 is the value passed in, which is distinct from the value of the
local variable COLOR. I agree. It's ugly.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.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
Previous Topic: From PV-WAVE to IDL
Next Topic: Re: Gridding options

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

Current Time: Fri Oct 10 18:07:25 PDT 2025

Total time taken to generate the page: 0.40170 seconds