Jeremy Howard wrote:
> Unless I'm missing something here, you're not filling in the args correctly.
> I think you mean:
> 
> $check = sub (;$$$$) {
>           @_==0 ?  __ < 2 + __ * atan($pi/__) or die __
>         : @_==1 ?  $_[0] < 2 + __ * atan($pi/__) or die __
>         : @_==2 ?  $_[0] < 2 + $_[1] * atan($pi/__) or die __
>         : @_==3 ?  $_[0] < 2 + $_[1] * atan($pi/$_[2]) or die __
>         :          $_[0] < 2 + $_[1] * atan($pi/$_[1]) or die $_[3]
>         ;
> };

And neither did you... ;) The last line should be:
>         :          $_[0] < 2 + $_[1] * atan($pi/$_[2]) or die $_[3]

That's why curried functions should automatically re-curry themselves
instead of depending upon lazy programmers. ;)

> > Arguments other than the last can also be bound by the explicit use of
> > placeholders:
> 
> What do you mean 'other than the last'. Isn't your example showing that
> _all_ the arguments can get bound?

Not really. In the last case the arguments don't get bound, they get
evaluated. (Since __ doesn't appear, the last case is just a plain
expression.) In all the other cases, the arguments are *not* evaluated
at all, only bound.

Of course, Damian may have meant 'other than the first' and just made
a mistake. The default for a curried function is to re-curry itself if
it is given less than the number of arguments it needs. The re-curry
binds from left to right (first to last). If you don't want the default
left to right binding, then you have to use __ to skip the arguments
you don't want to bind.

- Ken

Reply via email to