[Xotcl] new feature idea

Gustaf Neumann neumann at wu-wien.ac.at
Thu Sep 30 09:56:08 CEST 2010

Dear Victor,

yes, this looks nice. It is premature to add it to the set
of builtins, i have not had much uses cases for this functionality.
But as you say, it can be easily scripted (see below)....
or provided as and optional package.

>  This functionality is even more enhanced with mixins and
>  superclasses where each chained method would be passed to a
>  mixin/superclass via [next].

one could pass in the list of methods as well per-object 
which could be added before and removed after the invocation.
however, this would make invocation less elegant, and i doubt
that there are many use cases for this.

It is not fully clear what's the best way to return the results
or errors of the multiple method invocations. The small
implementation below returns a list of results of the
individual methods, and does nothing about errors.

we plan on the new web site a community space, where can
place some implementation studies like this one.

Btw., the "opposite" problem is to call a single method with
a set of argument vectors (the method is called repeatedly
with each element of the set). There is an implementation
of that in the new regression test using the tcl8.6 function
apply (similar in length to the example below).

-gustaf neumann

package require nx

nx::Object public method chain args {
   set methods [lrange $args 0 end-1]
   set arguments [lindex $args end]
   set result [list]
   foreach m $methods {
     lappend result [$m {*}$arguments]
   return $result

Class create MyClass {
   :method a {x y z} {
     return "a $x"
   :method b {x y z} {
     return "b $y"
   :create m1

puts [::m1 chain :a :b {1 2 3}]

More information about the Xotcl mailing list