Mod /
Tcl Mod
Search:  


Table Of Contents (show)

  1. 1. Tcl/Mod
    1. 1.1 Duplicate Commands
    2. 1.2 Tcl/Mod Command List

1.  Tcl/Mod

OBSOLETE

Tcl/Mod refers to the apparent new Tcl commands available with Mod's default uses for the re-factored Tcl's builtin commands. Default uses is the autoimport of subcommands from the following namespaces:

  ::info ::string ::file ::array ::namespace ::after ::clock ::interp ::package ::winfo ::wm ::font

(In fact, several other namespaces are also imported such as ::msgcat and the widgets from ::Tk.)

When autoimport applies to builtins, Tcl code can be more succinct, as illustrated by the following two procs. With Mod these two procs perform the same (admittedly contrived) purpose. However foo1 is more compact than foo2 because it can ommit command prefixes for well-known sub-commands.

    proc foo1 {cmd} {
        array set p { a 1 b 2 c 3 }
        set cns [namespace current]
        if {[array size p]>2 &&
         [namespace children $cns] != {} &&
         [namespace qualifiers $cns] != {} &&
         [namespace which -command ${cns}::foo1] != {}} {
             set v $cns
        }
        set k [file dirname $argv0]
        set m [file mtime $argv0]
        set exe [info nameofexecutable]
        if {[string first X $k]>=0 || 
        [string match Y* $k] ||
        [string is integer $k]} {
            set k [string map {X Y} $k]
            set m [string range $m 1 end]
            set exe [string tolower [string trim $exe]]
            set ext [file extension $exe]
        }
        if {[info complete $cmd] ||
        [string length $cmd]> 0} {    
            set l [string length $cmd]
            set s [clock clicks]
        }  
        if {[info exists l] &&
        [string equal $l Foo] &&
        [info commands ::$l] != {} 
        && [info hostname] != "dev"} {
            set scr [info script]
            set lev [info level]
        }
        interp alias {} xx {} yy -n 1
    }
    proc foo2 {cmd} {
        array set p { a 1 b 2 c 3 }
        set cns [current]
        if {[size p]>2 &&
         [children $cns] != {} &&
         [qualifiers $cns] != {} &&
         [which -command ${cns}::foo1] != {}} {
             set v $cns
        }
        set k [dirname $argv0]
        set m [mtime $argv0]
        set exe [nameofexecutable]
        if {[first X $k]>=0 ||
        [match Y* $k] ||
        [is integer $k]} {
            set k [map {X Y} $k]
            set m [range $m 1 end]
            set exe [tolower [trim $exe]]
            set ext [extension $exe]
        }
        if {[complete $cmd] ||
        [length $cmd]> 0} {    
            set l [length $cmd]
            set s [clicks]
        }  
        if {[exists l] && 
        [equal $l Foo] &&
        [commands ::$l] != {} && 
        [hostname] != "dev"} {
            set scr [script]
            set lev [level]
        }
        alias {} xx {} yy -n 1
    }

1.1  Duplicate Commands

Inevitably, common subcommand names end up occuring in more than one builtin command. There are 3 duplicated subcommands in the main Tcl group of commands:

  exists = ::info ::file ::namespace ::interp
  tail = ::file ::namespace
  delete =  ::file ::namespace ::interp

Thus the order of the namespace list specifies the preference, with later definitions having higher priority. However, as with all Tcl, local user defined commands override builtins.

1.2  Tcl/Mod Command List

With the apparent addition of new commands (See Docs), users of Mod have a new list of commands to memorize.

Base Tcl 8.5 defines (approximately) 90 commands at startup:

after append array auto_execok auto_import auto_load auto_load_index auto_qualify binary break case catch cd clock close concat continue dict encoding eof error eval exec exit expr fblocked fconfigure fcopy file fileevent flush for foreach format gets glob global history if incr info interp join lappend lassign lindex linsert list llength load lrange lrepeat lreplace lsearch lset lsort namespace open package pid proc puts pwd read regexp regsub rename return scan seek set socket source split string subst switch tclLog tell time trace unknown unload unset update uplevel upvar variable vwait while

However autoimport add about 105 well-known commands:

alias aliases args atime attributes body bytelength channels children clicks cmdcount code commands compare complete copy create current default delete dirname ensemble equal eval executable exists export expose extension first forget format functions globals hidden hide hostname import index inscope invokehidden is isdirectory isfile issafe join last length level library link loaded locals lstat map marktrusted match mkdir mtime nameofexecutable nativename normalize origin owned parent patchlevel pathtype procs qualifiers range readable readlink recursionlimit rename repeat replace rootname scan script seconds separator share sharedlibextension size slaves split stat system tail target tclversion tolower totitle toupper transfer trim trimleft trimright type vars volumes which wordend wordstart writable

Giving Tcl/Mod this list of 193 commands:

after alias aliases append args array atime attributes auto_execok auto_import auto_load auto_load_index auto_qualify binary body break bytelength case catch cd channels children clicks clock close cmdcount code comma commands compare complete concat continue copy create current default delete dict dirname encoding ensemble eof equal error eval exec executable exists exit export expose expr extension fblocked fconfigure fcopy file fileevent first flush for foreach forget format functions gets glob global globals hidden hide history hostname if import incr index info inscope interp invokehidden is isdirectory isfile issafe join lappend lassign last length level library lindex link linsert list llength load loaded locals lrange lrepeat lreplace lsearch lset lsort lstat map marktrusted match mkdir mtime nameofexecutable namespace nativename normalize open origin owned package parent patchlevel pathtype pid proc procs putc pwd qualifiers range read readable readlink recursionlimit regexp regsub rename repeat replace return rootname scan script seconds seek separator set share sharedlibextension size slaves socket source split stat string subst switch system tail target tclLog tclversion tell time tolower totitle toupper trace transfer trim trimleft trimright type unknown unload unset update uplevel upvar variable vars volumes vwait which while wordend wordstart writable

© 2008 Peter MacDonald

Page last modified on April 15, 2010, at 08:39 AM