[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keyword precedence



"David Fanning" <davidf@dfanning.com> wrote in message
MPG.140f8856ff9c2a24989bf1@news.frii.com">news:MPG.140f8856ff9c2a24989bf1@news.frii.com...
> I'm referring, of course, to those occasions when you
> absolutely, positively DON'T want the damn color to
> be mucked around with. Then you have to go fishing
> for the COLOR keyword in the extra structure. It would
> be OK if you could do something like this:
>
>    fields = Tag_Names(extra)
>    index = Where(fields EQ 'COLOR', count)
>    IF count GT 0 THEN extra.color = 127
>
> But, of course, the user didn't use COLOR as the keyword.
> They used C, CO, COL, COLO, or some other thing, and
> you have to fish those things out as well.

Thanks for your comments, David. It's nice to know that somebody reads my
raves.

Why not

pro my_plot, COLOR=color, _EXTRA=extra
    if n_elements(color) gt 0 then $
        message, /INFORM, "I'm plotting this in color index 127 whatever you
say!"
    plot, COLOR=127, _EXTRA=extra
end

or my preference

pro my_plot, COLOR=color, _EXTRA=extra
    if n_elements(color) gt 0 then $
        message, "Don't touch the friggin' COLOR!"
    plot, COLOR=127, _EXTRA=extra
end

> I think if a keyword is important, define it, and define
> a default value for it. I wouldn't change any of your fine
> code a bit, Mark.

I already have done in one or two places. It got clearer, in my opinion. But
it's a matter of taste.

There's nothing stopping me from writing in the comments header:

COLOR:    As for plot, but default is 127.

> Actually, I think this code is working exactly the way
> it is suppose to work. (Someone is going to have to pry
> JD away from this thesis for the definitive answer. I'm
> slightly confused about it too.)

At the moment when I write

foobar, COLOR=0, _EXTRA={color:12}

then if foobar is a wrapper for some other function (and foobar itself
doesn't have a COLOR keyword) I have to know whether foobar uses reference
or value inheritance to know what the effect will be. This can't be right!

Of course I don't actually write the above command, not unless I'm messing
about trying to understand inheritance mechanisms. But that's the effect of
some perfectly reasonable wrapper designs.

---
Mark Hadfield
m.hadfield@niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield/
National Institute for Water and Atmospheric Research
PO Box 14-901, Wellington, New Zealand