Version 2 of modify a proc's behavior with a shim

Updated 2010-07-17 19:17:57 by AMG

JBR 2010-07-12

I have a lot of code that writes code. Sometimes the "standard" code that gets written from the config files is not exactly the right thing for some specific case. When this happens I usually modify the standard proc by wrapping a "shim" around it. This little bit of code makes this less crappy. It is less general than the code in stacking but works for me.

 proc shim:shift { name } {
    if { [info commands ${name}_shimmed] ne {} } { shim:shift ${name}_shimmed }
    rename $name ${name}_shimmed
 }

 proc shim { name args body } {
    shim:shift $name
    proc   $name $args $body
 }

 proc shim:next { args } { tailcall [lindex [info level -1] 0]_shimmed {*}$args }