Version 6 of corp

Updated 2013-11-12 11:37:37 by RLE

Richard Suchenwirth 2006-01-29 - corp is proc in reverse. The latter defines a function, with name, argument list and body; the former reconstructs (serializes) that call back to a string that can be evaled. As added benefit, you also get a comment on where the proc came from, if available.

 proc corp name {
   if {[info exists ::auto_index($name)]} {
      set body "# $::auto_index($name)\n"
   } else {set body ""}
   append body [info body $name]
   set argl {}
   foreach a [info args $name] {
      if {[info default $name $a def]} {
         lappend a $def
      lappend argl $a
   list proc $name $argl $body

One possible use is to "ship" a procedure to another interpreter (e.g. for another thread):

 $interp eval [corp $procname]

This way, you can dispense procs as needed, without the other interp having to source everything. Or you can just type corp name at a console to inspect a proc.. or load into an editor for local modification, as seen in e: a tiny editor plugin for eTcl.

MSH 2006-04-26 corp is also the translation of BODY in French as in info body !

AK See also tkcon's dump command [L1 ], which can serialize many more things.