Version 20 of interp alias

Updated 2004-10-22 14:34:20

interp alias srcPath srcCmd

Returns a Tcl list whose elements are the targetCmd and args associated with the alias named srcCmd (all of these are the values specified when the alias was created; it is possible that the actual source command in the slave is different from srcCmd if it was renamed).

interp alias srcPath srcCmd {}

Deletes the alias for srcCmd in the slave interpreter identified by srcPath. SrcCmd refers to the name under which the alias was created; if the source command has been renamed, the renamed command will be deleted.

interp alias srcPath srcCmd targetPath targetCmd ?arg arg ...?

This command creates an alias between one slave and another (see the alias slave command below for creating aliases between a slave and its master). In this command, either of the slave interpreters may be anywhere in the hierarchy of interpreters under the interpreter invoking the command. SrcPath and srcCmd identify the source of the alias. SrcPath is a Tcl list whose elements select a particular interpreter. For example, "a b" identifies an interpreter b, which is a slave of interpreter a, which is a slave of the invoking interpreter. An empty list specifies the interpreter invoking the command. srcCmd gives the name of a new command, which will be created in the source interpreter. TargetPath and targetCmd specify a target interpreter and command, and the arg arguments, if any, specify additional arguments to targetCmd which are prepended to any arguments specified in the invocation of srcCmd. TargetCmd may be undefined at the time of this call, or it may already exist; it is not created by this command. The alias arranges for the given target command to be invoked in the target interpreter whenever the given source command is invoked in the source interpreter.

interp aliases ?path?

This command returns a Tcl list of the names of all the source commands for aliases defined in the interpreter identified by path.


Very often used to introduce command aliases inside the current interpreter (see Custom curry), where the alias target may well be a sequence of words:

 interp alias {} strlen {} string length

The case where source and target have identical signatures is Tcl's idiomatic way to write a command alias:

    interp alias {} new_name {} existing_command

This can be used with some punctuation to make code shorter and potentially more readable as long as the reader knows about the alias(es) in effect.

  interp alias {} @ {} lindex

See Transliteration of how to use an alias, besides its original function, as a kind of global data storage


Does anybody else here have the guts to admit to using echo instead of puts as often as possible? 8-)

Erm ... nope.

RS doesn't, but if you accept the puts API (only one string argument), here goes:

 interp alias {} echo {} puts

See also:


Cleverness due to dgp (and others):

  package require Tcl 8.5
  interp alias {} err {} return -code error -level 0

More generally, currying in other languages has these analogues, as mentioned above.


Tcl syntax help - Category Command - Category Introspection