No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] new feature idea
From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Thu, 30 Sep 2010 09:56:08 +0200
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}]
Date: Thu, 30 Sep 2010 09:56:08 +0200
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}]