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

Home » Public Forums » archive » Re: Passing zero as a Parameter/ NOT KEYWORD_SET
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: Passing zero as a Parameter/ NOT KEYWORD_SET [message #16071 is a reply to message #16067] Tue, 29 June 1999 00:00 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
J.D. Smith wrote:
>
>
> That's a bit dangerous. [...]
Indeed ;-)
>
> The best way to proceed is pretend keyword_set() was really
> named is_defined_and_non_zero(). Forget that it's called
> keyword_set().
In fact it is "is_defined_and_uneven" !
Just try to pass var=2 into a routine and print keyword_set(var). Hope,
David will take notice of this in his article.

Another marginal point about setting default values: I recently learned
from someone's code (cannot remember whose), to use
if (n_elements(var) ne 1) then var=default
instead of
if (n_elements(var) eq 0) then var=default

The advantage being that you can prevent program crashes when someone
passes a vector or array in what is supposed to be a scalar.

And, finally: Use keyword_set when you want to make sure the value of a
boolean flag is defined:
flag = keyword_set(flag)
Then, later in the code, it's just
if (flag) then ...
Or value = x+y*(flag), etc. which would crash otherwise.

Regards,
Martin.

|||||||||||||||\\\\\\\\\\\\\-------------------///////////// //|||||||||||||||
Martin Schultz, DEAS, Harvard University, 29 Oxford St., Pierce 109,
Cambridge, MA 02138 phone (617) 496 8318 fax (617) 495 4551
e-mail mgs@io.harvard.edu web http://www-as/people/staff/mgs/
[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
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Zero vector detection in IDL
Next Topic: Re: Extra space around widget windows....

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

Current Time: Wed Oct 08 20:15:03 PDT 2025

Total time taken to generate the page: 0.40314 seconds