http://qs321.pair.com?node_id=194120

in reply to Re: Isn't that nice?

I'm not sure, but maybe prebinding parameters?

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Re: Re: Isn't that nice?
by frankus (Priest) on Aug 30, 2002 at 15:15 UTC
Forgive the duff syntax, been busy and I can't find an example, I'd have thought the lecture notes would be available online somewhere.., and I can't recall all the details precisely.

```sub divide( \$x, \$y ) {
\$x / \$y
}

sub half assuming divide( \$y=2 )
Uh does that look familiar to anyone?

--

Brother Frankus.

Probably more like:
my &half := &divide.assuming( \$y => 2 )
But that's the general idea.

Larry

Apart from being substantially prettier, is this functionally or efficiently different from

```
my \$half =  sub { \$_[1]=2; goto &divide; };

print \$half->( 120 ),\$/;
__END__
60
?
Well It's better than the Abottoire, but Yorkshire!
It's just currying. The syntax is unique to perl, but the semantics are reasonably common in functional programming languages. The 'new' thing about perl 6's 'assuming' operator is that, according to Damian, it doesn't actually create a new function, but that's not really going to be user visible.

Yes, it looks a little bit like OCaml (i.e. I'm not sure this has never been seen in any other language). :-)

```# let divide ~x ~y = x / y;;
val divide : x:int -> y:int -> int = <fun>
# let half = divide ~y:2;;
val half : x:int -> int = <fun>
# half 120;;
- : int = 60