Re: Curious Keywords [message #8356] |
Mon, 03 March 1997 00:00  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
davidf@dfanning.com (David Fanning) writes:
> JD Smith writes in a follow-up to this thread:
(stuff deleted)
> JD is absolutely right about this. You cannot tell in an IDL procedure
> if a keyword is *used* or not. You can only tell if the argument to the
> keyword is *defined* or not.
> (Most of the programs I look at, by the way, mistakenly think this
> is what KEYWORD_SET is doing for them. Sigh...)
> Since knowing if a keyword is *used* is often quite useful for
> exactly the reasons JD mentions, I think it should be added to IDL.
> Obviously IDL knows if the keyword is being used.
> I think, if I remember correctly, that PV-Wave has a function
> entitled KEYWORD_USED (or something like it) that does this very thing.
On the other hand, I find it quite frustrating that I can't use a phrase like
IDL> plot, findgen(100), findgen(100)/99.*2*!PI, THICK=THICK
and not worry about whether or not THICK was defined. In some sense this is
what _EXTRA does, but that has its own limitations.
Of course, there have been instances when I wanted to do exactly what JD Smith
was talking about. The most obvious example is when I wanted error messages to
be returned to the user rather than printed on the screen. The only way to do
this was to force the calling routine to define the keyword before calling the
program, e.g.
ERRMSG = ''
MYROUTINE, ERRMSG=ERRMSG, ...
IF ERRMSG NE '' THEN ...
As pointed out, this is a pain.
In summary, I guess what would be best would be if the built-in routines were
more forgiving about passing undefined keywords, and also if there were a
KEYWORD_USED (or whatever) routine that would allow .PRO files to figure out
for themselves whether or not a keyword was really passed, even if undefined.
That way, we could eat our cake and have it too.
I would also like to echo David's comment about KEYWORD_SET(). I also find it
upsetting when people use this when they should have used N_ELEMENTS() instead.
(Double sigh.)
Bill Thompson
|
|
|