Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Walking with Tree (tcllib)

0 views
Skip to first unread message

David Bigelow

unread,
Apr 15, 2003, 11:59:39 PM4/15/03
to
Good people,

OK -- here is an interesting question.

I am using struct (tree - tcllib) on 8.4.1/2 and have found it a nice
addition to the toolbox for structuring data.

However, when I am walking through the tree and want to stop the walk
-- I can not seem to do it without causing a major error. I was
trying to add a "break" to the command loop - but it did not work as
expected.

I am using something similar to:

myTree walk $startNode -command {
if {"%n" == "0.7"} {
break ; # Get out of the walk!
} else {
.tb insert end "WALKED TO THIS: %n\n"
}
}

Note: "return" does not seem to do the trick either - and I really
would not like to use the return as I am trying to use this walk code
liek a foreach execept using the tree structure.

Anyone have any suggestions?

Dave

Brian Theado

unread,
Apr 16, 2003, 6:54:13 AM4/16/03
to

"David Bigelow" <davidh...@compuserve.com> wrote in message
news:712f19a1.03041...@posting.google.com...
[snip]

> However, when I am walking through the tree and want to stop the walk
> -- I can not seem to do it without causing a major error. I was
> trying to add a "break" to the command loop - but it did not work as
> expected.
[snip]

A few months ago, I wanted something similar--to have a "prune" command that
could be called within a walk script. This prune command would continue
walking, but not walk any of the descendents of the current node. After
playing around I found that the following had the behavior I wanted (at
least for depth first walking--I didn't try with any others):

return -code continue

I think if you want to stop the walk altogether, you could use (I haven't
tried this):

return -code break

This is very dependent on how the walk command is currently implemented, so
if it ever changes these may no longer work.

Brian Theado


0 new messages