Re: Oddball Event Handling (Longer than it Ought to Be) [message #23035 is a reply to message #23031] |
Sun, 31 December 2000 11:01   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
> Thanks for the cool description of you project.
>
> Now, prepare to be lightly toasted :-)
>
>> FUNCTION FindTLB, startID
>>
>> ; This function traces up the widget hierarchy to find the top-level base.
>>
>> FORWARD_FUNCTION FindTLB
>> parent = Widget_Info(startID, /Parent)
>> IF parent EQ 0 THEN RETURN, startID ELSE parent = FindTLB(parent)
>> RETURN, parent
>> END
>
> I have no problem with recursion. In this case however it's not
> really needed. For the book larnin' types, this is known as tail
> recursion I believe, which is often easily optimized. I admit
> recursion may help you conceptualize what's going on though. Wouldn't
> the following code do the same thing?
>
> parent = startid
> while widget_info(parent, /parent) NE 0 do $
> parent = widget_info(parent, /parent)
Oh, sure, it would *work*. But how you gonna give
something like that away? :-)
Apparently I didn't make it clear that I wasn't
looking for criticism of my exciting new program,
but I have to admit I fooled around for a few
minutes trying to get a WHILE loop to work. But
after becoming confused I just wandered around in
the wilderness for a while, making a change here,
and another change there for no apparent rational
reason (you know, how you do when you are improvising)
and all of a sudden, BLAM, something worked.
In my personal programming myth, if something works
it is clearly the most highly optimised solution.
But thanks for your suggestion. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|