[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing zero as a Parameter/ NOT KEYWORD_SET
- Subject: Re: Passing zero as a Parameter/ NOT KEYWORD_SET
- From: Martin Schultz <mgs(at)io.harvard.edu>
- Date: Tue, 29 Jun 1999 15:31:32 -0400
- Newsgroups: comp.lang.idl-pvwave
- Organization: Harvard University
- References: <377773B4.8DEAE40@garnet.acns.fsuMMER.edu> <377794eb.21566520@146.80.9.44> <37777E20.353D94CA@garnet.acns.fsuMMER.edu> <7lacrl$jq9$1@news6.svr.pol.co.uk> <3778D9D8.75C8E770@astrosun.tn.cornell.edu>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:15454
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/