Hello Gustaf, Is it possible to have an alias to ensemble or multi-word commands? Example:
Obj public alias string_length "::string length" or Obj public alias "string length" "::string length"
Thanks
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
Thanks Stefan,
I already knew about the "forward" method, the reason I asked about "alias" is that I noticed that it is a bit faster than "forward".
On Thu, Jan 5, 2012 at 2:22 PM, Stefan Sobernig stefan.sobernig@wu.ac.at wrote:
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]
This should work, thanks.
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
In cases, where no ensemble command is available from tcl, one can use as an additional option to the forward an interp alias like in the following example:
% package req nx % interp alias {} foo {} string is boolean % foo true 1 % foo hi 0 % Object create o { :public alias stringIsBoolean foo } ::o % o stringIsBoolean true 1
-gustaf neumann
On 05.01.12 23:22, Stefan Sobernig wrote:
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 _______________________________________________ Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl