Posted to tcl by Poor Yorick at Wed Feb 05 02:49:43 GMT 2014view pretty

#! /bin/env tclsh

proc alias {alias target} {
        set fulltarget [uplevel [list namespace which $target]]
        namespace eval [namespace qualifiers $fulltarget] \
                [list namespace export [namespace tail $fulltarget]]
        set newcmd [namespace eval [info cmdcount] [string map [
                list @{alias} [list $alias] @{fulltarget} [list $fulltarget] ] {
                namespace import @{fulltarget}
                rename [namespace tail @{fulltarget}]  @{alias}
                ::namespace export @{alias}
                ::namespace which @{alias}
        }]]
        uplevel [list namespace import $newcmd]
        uplevel [list trace add command $fulltarget delete [list apply [list {stash args} {
                namespace delete [namespace qualifiers $stash]
        }] $newcmd]]
}

proc proc1 args {}
alias newproc proc1
proc proc1 {} {}