Posted to tcl by aspect at Sat May 21 06:56:44 GMT 2011view pretty
proc unknown {cmd args} { upvar 1 $cmd cmdvar if {[info exists cmdvar]} { uplevel 1 [list $cmdvar {*}$args] } else { apply $cmd {*}$args } } # now we can dispense with [proc]! set lambda {{args body} {list $args $body}} set proc {{name args body} {uplevel 1 [list set $name [list $args $body]]}} # scheme's (define) for Tcl set define {{name value} { if {[llength $name] > 1} { set args [lassign $name name] set value [list $args $body] } set $name $value } define {square a} {* a a} # an accumulator proc accumulator {initial} { lambda {addend} { incr initial $addend } } # is there room to attach bytecode to a variable that contains a lambda? # we still lack proper closures. [sproc] seems to have an approach for that. # hygienic macros are completely another story