Re: Meta- and Hyperoperators and Anonymous Subroutines
2009/3/2 Moritz Lenz : > Thomas Chust wrote: >> [...] >> Therefore I think that it would be a nice addition for Perl 6 if the >> X...X, <<...>> and similar operators could be applied to anonymous >> subroutines in addition to other operators. If such a syntactic change >> wasn't possible it would probably be worthwhile to offer methods like >> map and fold on array instances that take subroutine references as an >> alternative. > > There are already. You could write my example above also as > > @values.map(&map_function).reduce(&reduce_function) > [...] Thanks for pointing this out. Apparently I must have overlooked them or looked at outdated documentation. cu, Thomas -- When C++ is your hammer, every problem looks like your thumb.
Re: Meta- and Hyperoperators and Anonymous Subroutines
Hi, Thomas Chust wrote: > Hello, > > looking into Perl 6 syntax I noticed that there are meta- and > hyperoperators to perform among others the classical functional map > and fold operations. However, if I understood this correctly, you can > only use these constructs to lift scalar *operators* to the domain of > arrays. For operators there are meta-operators. For functions there are functions: reduce &reduce_function, map &map_function @values; Note that the biggest advantage of things like [**] is that they automatically obey the associativity rules for the operator infix:<**>. Since subs have no associativity, I don't see a big advantage in having a reduce-for-functions or map-for-functions operator. > Therefore I think that it would be a nice addition for Perl 6 if the > X...X, <<...>> and similar operators could be applied to anonymous > subroutines in addition to other operators. If such a syntactic change > wasn't possible it would probably be worthwhile to offer methods like > map and fold on array instances that take subroutine references as an > alternative. There are already. You could write my example above also as @values.map(&map_function).reduce(&reduce_function) Cheers, Moritz -- Moritz Lenz http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/
Meta- and Hyperoperators and Anonymous Subroutines
Hello, looking into Perl 6 syntax I noticed that there are meta- and hyperoperators to perform among others the classical functional map and fold operations. However, if I understood this correctly, you can only use these constructs to lift scalar *operators* to the domain of arrays. Coming from a functional programming background (I write a lot of Scheme code), I am very much accustomed to use map and fold operations, but experience teaches me that a lot the the expressive power offered by these operations comes not from the ability to pass a predefined operator to them but rather from the fact that one can also easily pass a custom operation. Therefore I think that it would be a nice addition for Perl 6 if the X...X, <<...>> and similar operators could be applied to anonymous subroutines in addition to other operators. If such a syntactic change wasn't possible it would probably be worthwhile to offer methods like map and fold on array instances that take subroutine references as an alternative. cu, Thomas -- When C++ is your hammer, every problem looks like your thumb.