Version 3 of Tcl in tcl

Updated 2003-08-02 20:04:45

The discussion of If we had no if got me thinking - what core commands can be written in terms of other core commands, and which are just syntactic sugar or optimizations? Maybe if we could hook into eval to redo tcl's read-eval-print loop then things like proc become a simple lookup into a hashtable, a few sets and another eval..

Maybe something like

 proc eval {command args} {
   if {[info procs $command] == $command} {
     foreach [info args $command] $args break
     eval [info body $command]
   } elseif {[info commands $command] == $command} {
     $command $args
   }
 }

A little rough around the edges, but I never claimed to have fully thought it through ...


Are there not already core tcl commands that are defined as tcl procs?


TIP 90 removed the last barrier to being able to create a proc for each built-in Tcl command that behaves exactly like that built-in Tcl command. That is, for every built-in [foo], you can now create a corresponding [myFoo] that is a proc and behaves the same.

The proc replacement may need to call the original built-in command, if it exposes functionality not available any other way, for example consider [socket].


category internals