[[Wiki formatting rules]]
CAU - Have you seen these : Bag of number/time spellers ?Arlie - It looks similar to what I'm planning to work on.
o August 16, 2006Arlie - I tried my hands on Gadgets and found it very interesting but I was not successfull in running the shorter version of Larry Smith.
proc gadget { unused type methods } { set typeproc { set typeproc { upvar @var self @type self $method $args } upvar $var self if { "$method" == "" } { return $self } switch $method { @methods } regsub @var $typeproc $var typeproc proc $var { { method "" } args } $typeproc } regsub @type $typeproc $type typeproc regsub @methods $typeproc $methods typeproc proc $type { var method args } $typeproc }Running the test code I got this output:
gadget type number { = {set self [expr $args]} ++ {set self [expr $self+1]} round {set self [expr round($self)]} sqrt {expr sqrt($self)} } gadget type int { = {set self [expr round($args)]} ++ {incr self} } gadget type Array { = - += {eval array set self $args } -= {catch {unset self($args)}} @ {set self($args)} empty {expr [array size self]==0} names {array names self} {} {array get self} } gadget type List { = {eval set self $args} += {lappend self $args} @ {lindex $self $args} empty {expr [llength $self]==0} sort {lsort $self} length {llength $self} } gadget type File { = {set self [eval open $args]} >> {upvar $args var; expr [gets $self var]+1} << {puts $self $args} eof {eof $self} open? {expr ![catch {seek $self 0 current}]} close {close $self} } 1 % number N = 1.5 2 % Array A wrong # args: should be "Array var method args" 3 % List L = {foo bar} 4 % N = [N] * $N 5 % set A(cat) Katze Katze 6 % A names wrong # args: should be "Array var method args" 7 % L += grill 8 % L = [L sort] 9 % puts "[L] has [L length] elements, second is [L @ 1]" {} has elements, second is 10 % 10 % File F = "c:/gadget.tcl" 11 % int i = 1 12 % while {[F >> line]} { > puts [i]:$line > i ++ > } variable "var" already exists 13 % F close 14 %Can anyone help me on this?