Thanks Gustaf and Artur!<br><br>Not sure if this should be considered expected behaviour - but does the type have to be defined before declaration?<br>This simple script illustrates the issue - see the last couple of attempts.
<br><br>Class Base -slots { Attribute connects_to -multivalued true -type Base }<br>Class DerivedA -superclass Base -slots { Attribute connects_to -multivalued true -type DerivedB }<br>Class DerivedB -superclass Base -slots { Attribute connects_to -multivalued true -type DerivedA }
<br><br>Base b<br>DerivedA da<br>DerivedB db<br><br>b connects_to add da<br>b connects_to add db<br><br>db connects_to add b<br>>>> can't set "connects_to": b is not of type DerivedA << This should be expected. all A-ok.
<br><br>db connects_to add da<br>da connects_to add b<br>>>> can't set "connects_to": bad class "DerivedB": must be alnum, alpha, ascii, control, boolean, digit, double, false, grap<br>h, integer, lower, print, punct, space, true, upper, wordchar, or xdigit
<br><br>da connects_to add db<br>>>> can't set "connects_to": bad class "DerivedB": must be alnum, alpha, ascii, control, boolean, digit, double, false, grap<br>h, integer, lower, print, punct, space, true, upper, wordchar, or xdigit
<br><br><br><div class="gmail_quote">On Nov 7, 2007 12:06 AM, Gustaf Neumann <<a href="mailto:neumann@wu-wien.ac.at">neumann@wu-wien.ac.at</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Shishir Ramam schrieb:<br><div class="Ih2E3d">> Hi,<br>> I have a need to represent a directed graph in XoTcl.<br></div>Here are two small examples for representing graphs<br><br>In version one, edges are lists of references to nodes stored
<br>as attributes of nodes. By specifying "-multivalued true", it<br>is possible to "add" or "delete" elements from the list.<br>By using "-type Node" the code ensures, that only instances
<br>of Node may be added to the list, otherwise an error is thrown.<br><br> Class Node -slots {<br> Attribute connects_to -multivalued true -type Node<br> }<br><br> Node n1<br> Node n2<br> Node n3<br><br> n1 connects_to add n2
<br> n1 connects_to add n3<br><br> puts [n1 connects_to]<br><br>A "destroy" of a nodes automatically destroys the<br>edges as well, by refining the destroy method, one<br>could as well destroy the referenced edges (similar
<br>to aggregation (nesting objects), but one has to be<br>care about cyclical edges.<br><br>Another approach is to define Edges as objects<br>which makes it possible to provide methods for<br>Edges and to store attributes in it.
<br><br> Class Edge -slots {<br> Attribute from -type Node<br> Attribute to -type Node<br> }<br><br> Edge e1 -from n1 -to n2<br> Edge e2 -from n1 -to n3<br><br>Simarly as above, when a dynamic graph<br>is to be maintained, the destroy method of Node
<br>should care about deleting references in Edges<br>to ensure referencial integrity.<br>The easiest way is to check in the destroy method<br>of Node all Edges with [Edge info instances], if<br>their "form" or "to" attributes contain the node.
<br>One could as well build an index to make this<br>operation faster for large graph via a constructor<br>of Edge, which maintains e.g. a list of referenced<br>edges per node (e.g. via multivalued attribute<br>"references", similar to approach 1)
<br><font color="#888888"><br><br>-gustaf neumann<br><br></font></blockquote></div><br><br clear="all"><br>-- <br>Don't worry about people stealing an idea. If it's original, you will have to ram it down their throats.
<br> - Howard Aiken