Hola... I've spend some time these last few days slowly getting currying to work in pugs.
L<S06/Currying> states: "takes a series of named arguments"
The way binding is implemented in pugs does not seem to require
limiting that usage case. We have 2 functions, that operate on a
subroutine (which knows it's params):
bind some params
finalize bindings
bind some params will return a derived subroutine, with some params
prebound. assuming does just this.
finalize bindings will bind defaults to optionals, and check that we
have enough invocants and requireds bound, and return a derived
subroutine, with all params bound.
This is passed to the code that applies the sub.
The algorithmic approach to binding some params:
bind invocants
bind named parameters, and keep leftover pairs for %_
treat nonpairs as positionals, and bind them sequentially. Left
over nonpairs get put in @_
if we have slurpy params, they act as %_ and @_.
package a sub with the bindings, and the unbound params, and
return it.
and, well... that's it.
This has some funny properties, like:
foo ($x) { ... }
foo(x => 1, x => 2); # yields $x = 1, %_<x> = 2
foo(1, x => 2); # $x = 2, @_[0] = 1
(&foo.assuming(1))(x => 2); # $x = 1, %_<x> = 1
Are these bugs? I could live with them, but they are a bit
perl5-ish.
I think we need a little more guidance, as the exact semantics of
currying are not that well defined.
--
() Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418 perl hacker &
/\ kung foo master: *shu*rik*en*sh*u*rik*en*s*hur*i*ke*n*: neeyah!!!!
pgpE3lXT1h65V.pgp
Description: PGP signature
