----- Original Message ----- 
From: "Luke Palmer" <[EMAIL PROTECTED]>

> Joe Gottman writes:
> > 3)  Currying binds a function parameter to a value?  Is there any way to
> > bind a function parameter to a variable?  Consider the following code:
> >
> >     sub printNum(int $x) {print "$x\n";}
> >     my $foo = 0;
> >     my $vindaloo = &printNum(int).assuming(x => $foo); #currying
> >     ++$foo;
> >     $vindaloo.();
> >
> >    This code prints 0, not 1, because the currying binds the parameter
to
> > the value $foo had when the currying occurred, not the value it had when
the
> > curried function was called.  It would be nice if there were some way to
> > curry so that a parameter is bound to a variable reference.
>
> There is.  Best not to worry .assuming with details of references.  Do
> it with a scratchpad:
>
>    sub printNum($x) { print "$x\n" }
>    my $foo = 0;
>    my $vindaloo = { printNum($foo) };
>    ++$foo;
>    $vindaloo();   # Prints 1
>
> There's still those issues of getting $vindaloo's signature exactly
> right for complex cases.  In any case, I don't think .bind would be hard
> to write.
>
>
> > This would probably have to be a different method than assuming.
> > Maybe something like &printNum(int).bind(x => \$foo)

   But getting the signature of the returned code object right is a major
reason for using any kind of currying function instead of just writing a
scratchpad.  Getting the signature right is a non-trivial task, and
.assuming and .bind would have to do exactly the same work to compute the
signature.  Therefore, if we are defining one in the core I think we might
as well define the other as well.

Joe Gottman


Reply via email to