in reply to Re^5: Near-free function currying in Perl
in thread Near-free function currying in Perl
For instance, your technique would not work with OO, ...Why not? For example, here I use currying to pre-bind a method to a particular object instance:
Also, regarding this:#!/usr/bin/perl package MyObj; use warnings; use strict; use AutoCurry ':all'; sub new { my $self = shift; my $name = shift; bless [$name, { @_ }], $self; } sub speak_keyvals { my ($name, $hash) = @{shift()}; print "$name sez: @{[ @$hash{@_} ]}", $/; } my $foo = new MyObj( "foo", a => "alpha", b => "beta" ); $foo->speak_keyvals( "a" ); # foo sez: alpha # for the next line, recall that $o->f(...) === f($o, ...) my $foo_speaker = $foo->speak_keyvals_c(); # binds to $foo $foo_speaker->("b"); # foo sez: beta $foo_speaker->(@$_) for ["a"], ["b"], ["a", "b"]; # foo sez: alpha # foo sez: beta # foo sez: alpha beta
I also take issue with the idea that there is something wrong with design-time decisions to support currying.To clarify, I didn't say that there was anything wrong with design-time consideration of currying. What I said was that it was a bad idea to require design-time considerations in order to make a currying scheme work. With such a requirement, the vast existing wealth of CPAN is placed beyond the reach of currying.
I don't want my ability to use currying to be dependent upon somebody else having designed it into the code I'm using. I want to be able to take old, existing code and curry it, as is.
Cheers,
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: Near-free function currying in Perl
by stvn (Monsignor) on Nov 17, 2004 at 22:57 UTC | |
by FoxtrotUniform (Prior) on Nov 18, 2004 at 08:13 UTC | |
by dragonchild (Archbishop) on Nov 18, 2004 at 12:57 UTC | |
by tilly (Archbishop) on Nov 18, 2004 at 17:23 UTC | |
by Jenda (Abbot) on Dec 12, 2004 at 23:48 UTC | |
by BrowserUk (Patriarch) on Dec 13, 2004 at 06:08 UTC | |
by tilly (Archbishop) on Dec 13, 2004 at 17:55 UTC | |
by dragonchild (Archbishop) on Dec 13, 2004 at 15:00 UTC | |
by stvn (Monsignor) on Nov 18, 2004 at 14:05 UTC | |
by FoxtrotUniform (Prior) on Nov 18, 2004 at 19:55 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2004 at 20:55 UTC | |
| |
by stvn (Monsignor) on Nov 18, 2004 at 22:03 UTC |