if [llength [info commands p7proc]] { set Compiling true } else { set Compiling false source testing.tcl } set PrimitiveTypes { int tcl double } set ComplexTypes { Foo dict int* Foo* int** Foo** int*** } set ComplexTypes { Foo dict int* Foo* dict* int** Foo** dict*** int*** } if $Compiling { p7class Foo { (tcl)item (Foo)next } foreach T [concat $PrimitiveTypes $ComplexTypes] { # expand vnew, vset, vlen, and vget for type T p7source vec.p7i TYPE $T # return the "zero element" for type T p7proc ($T)zero<$T> {} " set ($T)z ; set z " } foreach T $ComplexTypes { if [regexp {[*]$} $T] { # elements are vectors -- need a size for new p7proc ($T)new<$T> {} " new ($T) 3 " } else { # elements are not vectors p7proc ($T)new<$T> {} " new ($T) " } } } else { foreach T $PrimitiveTypes { set v [vnew<$T> 5] AssertEq 5 {vlen $v} vset $v 1 11 vset $v 4 44 AssertEq [zero<$T>] {vget $v 0} AssertTrue { 11 == [vget $v 1] } AssertTrue { 44 == [vget $v 4] } } foreach T $ComplexTypes { set v [vnew<$T> 5] AssertEq 5 {vlen $v} set obj1 [ new<$T> ] set obj4 [ new<$T> ] vset $v 1 $obj1 vset $v 4 $obj4 AssertEq [zero<$T>] {vget $v 0} AssertTrue { $obj1 == [vget $v 1] } AssertTrue { $obj4 == [vget $v 4] } } Okay }