[Xotcl] new feature idea
Victor Mayevski
vitick at gmail.com
Fri Oct 1 06:34:24 CEST 2010
Thanks, I am looking forward into discussing this in the future.
----- Original Message -----
From: "Gustaf Neumann" <neumann at wu-wien.ac.at>
To: xotcl at 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 at alice.wu-wien.ac.at
http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
More information about the Xotcl
mailing list