Index: doc/example-scripts/rosetta-constraint-genericity.html =================================================================== diff -u -r24cb8f4bffd49c9375c1c64aa0610933b62511bb -rc4f449cb353be812ba6502ef8e9587e87881f59b --- doc/example-scripts/rosetta-constraint-genericity.html (.../rosetta-constraint-genericity.html) (revision 24cb8f4bffd49c9375c1c64aa0610933b62511bb) +++ doc/example-scripts/rosetta-constraint-genericity.html (.../rosetta-constraint-genericity.html) (revision c4f449cb353be812ba6502ef8e9587e87881f59b) @@ -1,855 +1,855 @@ - - - - - -Listing of doc/example-scripts/rosetta-constraint-genericity.tcl - - - - - -
-
-

Rosetta Example: Constrained genericity

-
- -
-
-
package req nx
-

Define the two classes Eatable and Fish. Eatable is a class -for all eatable things, a Fish is a subclass ant therefore -eatable.

-
-
-
nx::Class create Eatable
-nx::Class create Fish -superclass Eatable {
-  :property name
-}
-

A FoodBax may only contain eatable items. Therefore with we define -items as a property of type Eatable" which has a multiplicity of -+0..n (might contain 0 to n eatable items). Furthermore, we define -items as incremental, such we can add / remove items with item -add or item remove.

-
-
-
nx::Class create FoodBox {
-  :property -incremental item:object,type=::Eatable
-  :public method print {} {
-    set string "Foodbox contains:\n"
-    foreach i ${:item} {append string "   [$i cget -name]\n"}
-    return $string
-  }
-}
-
-

Demonstrating the behavior in a shell:

-

Create two fishes, Wanda and Nemo:

-
-
-
% set f1 [Fish new -name "Wanda"]
-% set f2 [Fish new -name "Nemo"]
-

Create a Foodbox and add the two fishes:

-
-
-
% set fb [FoodBox new]
-% $fb item add $f1
-% $fb item add $f2
-

Return the print string of the contents:

-
-
-
% $fb print
-Foodbox contains:
-   Nemo
-   Wanda
-
-
-
-
-

- - - + + + + + +Listing of doc/example-scripts/rosetta-constraint-genericity.tcl + + + + + +
+
+

Rosetta Example: Constrained genericity

+
+ +
+
+
package req nx
+

Define the two classes Eatable and Fish. Eatable is a class +for all eatable things, a Fish is a subclass ant therefore +eatable.

+
+
+
nx::Class create Eatable
+nx::Class create Fish -superclass Eatable {
+  :property name
+}
+

A FoodBax may only contain eatable items. Therefore with we define +items as a property of type Eatable" which has a multiplicity of ++0..n (might contain 0 to n eatable items). Furthermore, we define +items as incremental, such we can add / remove items with item +add or item remove.

+
+
+
nx::Class create FoodBox {
+  :property -incremental item:object,type=::Eatable
+  :public method print {} {
+    set string "Foodbox contains:\n"
+    foreach i ${:item} {append string "   [$i cget -name]\n"}
+    return $string
+  }
+}
+
+

Demonstrating the behavior in a shell:

+

Create two fishes, Wanda and Nemo:

+
+
+
% set f1 [Fish new -name "Wanda"]
+% set f2 [Fish new -name "Nemo"]
+

Create a Foodbox and add the two fishes:

+
+
+
% set fb [FoodBox new]
+% $fb item add $f1
+% $fb item add $f2
+

Return the print string of the contents:

+
+
+
% $fb print
+Foodbox contains:
+   Nemo
+   Wanda
+
+
+
+
+

+ + +