Index: doc/example-scripts/rosetta-multiple-distinct.html =================================================================== diff -u -r8648ec770a59ed911769dd51cf2658045110c748 -rc4f449cb353be812ba6502ef8e9587e87881f59b --- doc/example-scripts/rosetta-multiple-distinct.html (.../rosetta-multiple-distinct.html) (revision 8648ec770a59ed911769dd51cf2658045110c748) +++ doc/example-scripts/rosetta-multiple-distinct.html (.../rosetta-multiple-distinct.html) (revision c4f449cb353be812ba6502ef8e9587e87881f59b) @@ -1,830 +1,830 @@ - - - - - -Listing of doc/example-scripts/rosetta-multiple-distinct.tcl - - - - - -
-
-

Rosetta example: Multiple distinct objects

-
-

Create a sequence (array, list, whatever) consisting of n distinct, -initialized items of the same type. n should be determined at -runtime.

- -
-
-
package req nx
-

The class Klass defines and implements the item type. It can also -be used to query its population of instances.

-
-
-
nx::Class create Klass
-set n 100; # runtime parameter
-

Wrong: Only a single item (object) is created, its (command) name is replicated n times.

-
-
-
% llength [Klass info instances]
-0;
-
-set theList [lrepeat $n [Klass new]]
-
-% llength [Klass info instances]
-1;
-% llength [lsort -unique $theList]
-1;
-
-[lindex $theList 0] destroy
-

Correct: n items (objects) having distinct (command) names are -created and stored in the list.

-
-
-
% llength [Klass info instances]
-0;
-
-set theList {}
-
-for {set i 0} {$i<$n} {incr i} {
-    lappend theList [Klass new]
-}
-
-% llength [Klass info instances]
-100;
-% llength [lsort -unique $theList]
-100;
-
-
-
-

- - - + + + + + +Listing of doc/example-scripts/rosetta-multiple-distinct.tcl + + + + + +
+
+

Rosetta example: Multiple distinct objects

+
+

Create a sequence (array, list, whatever) consisting of n distinct, +initialized items of the same type. n should be determined at +runtime.

+ +
+
+
package req nx
+

The class Klass defines and implements the item type. It can also +be used to query its population of instances.

+
+
+
nx::Class create Klass
+set n 100; # runtime parameter
+

Wrong: Only a single item (object) is created, its (command) name is replicated n times.

+
+
+
% llength [Klass info instances]
+0;
+
+set theList [lrepeat $n [Klass new]]
+
+% llength [Klass info instances]
+1;
+% llength [lsort -unique $theList]
+1;
+
+[lindex $theList 0] destroy
+

Correct: n items (objects) having distinct (command) names are +created and stored in the list.

+
+
+
% llength [Klass info instances]
+0;
+
+set theList {}
+
+for {set i 0} {$i<$n} {incr i} {
+    lappend theList [Klass new]
+}
+
+% llength [Klass info instances]
+100;
+% llength [lsort -unique $theList]
+100;
+
+
+
+

+ + +