It occurred to me that XOTcl could benefit or it's "coolness" value could be raised even more if it had method chaining similar to JQuery. Example:
Class create Myclass
Myclass :method a args { process {*}$args; }
Myclass :method b args { process {*}$args; }
Myclass create myobj
execute:
myobj :chain :a :b {value1 value2}
or:
myobj :chain :a :b :a :b :destroy {value1 value2}
################ syntax:
obj :chain :method1 :method2 .... {arg1 arg2 ...}
################ functionality:
each method would be executed in the order listed with the args provided in the end of the "chain" method. ################
This functionality is even more enhanced with mixins and superclasses where each chained method would be passed to a mixin/superclass via [next].
P.S. this is not really a feature request at the moment because I see you are very busy doing a lot of work on Next. And that has more priority. Also, the "chain" functionality can be easily done via scripting it myself. Again, for the "coolness" or "extra power" value, it would be nice to have that, in my opinion, as a built-in feature.
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 mixins, 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}]
Thanks, I am looking forward into discussing this in the future.
----- Original Message ----- From: "Gustaf Neumann" neumann@wu-wien.ac.at To: xotcl@alice.wu-wien.ac.at Sent: Thursday, September 30, 2010 12:56:08 AM GMT -08:00 US/Canada Pacific Subject: Re: [Xotcl] new feature idea
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 mixins, 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}]
_______________________________________________ Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl