Updated 2017-07-17 19:08:52 by RKzn

[General meaning in software]

[much used in Tcl]

In Tcl, to enhance a core command (or existing proc) by renaming the command to be enhanced, then creating a procedure with the same name as the core command that provides the desired functionality.

Easy example, provided by RS:
    rename exit _exit

    proc exit {{code 0}} {
        set fp [open test a]
        puts $fp "trapped exit at [clock format [clock seconds]]"
        _exit $code
    }

General case needs uplevel, as in
         uplevel 1 [linsert $args 0 _original_PROC]

or, with 8.5,
         uplevel 1 [list _original_PROC {*}$args]

See stacking.