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
In reply to Re^6: Near-free function currying in Perl
by tmoertel
in thread Near-free function currying in Perl
by tmoertel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |