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

::struct::graph

76 views
Skip to first unread message

Frank

unread,
Jun 2, 2016, 1:14:19 AM6/2/16
to
Hi,

I am playing for the first time with ::struct::graph and realized there is no way to get the list of graphs or to test if a graph exists.

It seems the way to do this is to store the graph names in a variable as a list or array and then check the variable for the existence of the graph.

I hit this problem because I accidentally had a collision of graph names and an error gets generated during graph creation if a graph with the same name already exists.

Then I decided that I would like to destroy all the graphs and realized there was no way to get the names either and to destroy a graph I need the name "graphName destroy".

Shouldn't this package have a way to get all the graphs and test if they exists?

If the programmer does not keep track of the graph names or unsets the variable with the graph names __before__ destroying the graphs the graphs will remain in memory. A potential memory leak.

Am I missing something?

Thanks in advance,
Frank

heinrichmartin

unread,
Jun 2, 2016, 5:29:30 AM6/2/16
to
On Thursday, June 2, 2016 at 7:14:19 AM UTC+2, Frank wrote:
> I am playing for the first time with ::struct::graph and realized there is no way to get the list of graphs or to test if a graph exists.
>
> [...]
>
> Then I decided that I would like to destroy all the graphs and realized there was no way to get the names either [...]

You need to rely on the implementation, which is not good practice, but it works:

proc all_graphs {} {
lmap a [interp aliases] {
if {"::struct::graph::GraphProc" eq [lindex [interp alias {} $a] 0]} {
set a
} else {
continue
}
}
}

> Shouldn't this package have a way to get all the graphs and test if they exists?

tdom has a nice way to handle auto-cleanup. Even if the package does not support it natively, you could wrap (or override) the creation of the graphs and attach a trace for variable unset (assuming that you store the name of the graph in a variable).

Frank

unread,
Jun 2, 2016, 2:53:41 PM6/2/16
to
Thanks.

That does the trick of getting the graphs. I'll take a look at the package code to see if there is something that can be done on it to provide this functionality. I think it is a nice thing to have and should not be too hard to implement.
0 new messages