Phoenix.pm: quoting constant hash keys survey
Scott Walters
scott at illogics.org
Sat Apr 17 12:41:52 CDT 2004
By the way, as part of my little project, I wrote autobox::Core to
compliment autobox on CPAN, so you can do something a lot like this,
minus named parameters and placeholders, in Perl 5:
use autobox;
use autobox::Core;
sub { $_[0] + $_[1] }->curry(15)->(30); # 45
autobox::Core just provides wrappers for things that are already built into
core so they can be used as methods on primitive types (as well as a few things
that *will* be in core, such as curry).
autobox::Core, among other Perl 6isms, was the subject of a PM presentation
recently by the way ;)
-scott
On 0, Scott Walters <scott at illogics.org> wrote:
>
> Originally it was proposed that currying happen automatically in codereference
> context (Perl 6 has numerous contexts, rather than just void, scalar and list)
> and a routine could accept more named parameters than it was given, but it was
> decided that this was too automatic (though very cool), so the current plan is
> that code references have a curry method:
>
> sub ($foo, $bar) { $foo + $bar }.curry(15).(30); # 45
>
> That's position parameters.
>
> sub ($foo, $bar) { $foo + $bar }.curry(foo => 15).(bar => 30); # 45
>
> That's using named parameters. Come to think of it, named parameters and currying
> aren't as automatic as currying should be, but this works well with placeholders:
>
> sub { $^a + $^b }.curry(15).(30); # 45
>
> Of course, this all works on code references, too, which look like &foo
> (rather than \&foo as in P5).
>
> -scott
>
>
>
> On 0, eden li <eden.li at asu.edu> wrote:
> >
> > Ooo nice. I should pay more attention to Perl6's development. I wonder if they're gonna implement any of the currying features we had discussed at PM before. (i.e. defining a unary function that can be applied to any number of arguments ala lambda calculus).
> >
> > Anyway, back to the vote, in case it wasn't clear. My vote is a yea for `.
> >
> > Scott Walters wrote:
> > > String concat has been renamed ~ from _. . is method call. Primitive
> > > types "autobox" now, so you can ask an array for a length or a hash
> > > for its keys:
> > >
> > > %hash.keys # method call
> > >
> > > So, people have adopted the dot for method calls, and JavaScript uses the
> > > dot for both method calls and hash subscripts (as well as array indices),
> > > but since we could be either calling a method or subscripting a primitive,
> > > we have to tell perl which it is or risk confusion when we can't access
> > > hash subscripts with the same name as methods.
> >
More information about the Phoenix-pm
mailing list