View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] ensemble alias

From: Stefan Sobernig <stefan.sobernig_at_wu.ac.at>
Date: Thu, 05 Jan 2012 23:22:28 +0100

Victor,

> Is it possible to have an alias to ensemble or multi-word commands?

Well, namespace ensembles are straight forward; you may find out the
ensembled Tcl commands using e.g. [namespace ensemble configure string
-map] and then use the fully-qualified command names as alias target:

package req nx::test

Object create o {
   :public alias stringLength ::tcl::string::length
}

? {o stringLength "xyz"} [string length "xyz"]

If you don't have an ensemble command at hand (e.g., the [string is]
classes such as "integer", "boolean"), you want to bind in terms of a
method, consider a forwarder:

o public forward stringIsBoolean string is boolean

? {o stringIsBoolean "false"} [string is boolean "false"]

A forwarder is needed, because the "boolean" selector does not map to a
Tcl command, rather is an argument to a paramteric Tcl command
(::tcl::string::is).

A mixed alternative would be ...

o public alias stringIs ::tcl::string::is
o public forward stringIsBoolean2 %self stringIs boolean

? {o stringIsBoolean2 "false"} [string is boolean "false"]

//stefan