in reply to Re^3: Why not support this syntax?
in thread Why not support this syntax?
Good idea, and we can even cover that one ourselves, too:
sub is_ordered_according_to { my ($binary_predicate, @values) = @_; if (@values < 3) { return $binary_predicate->(@values); } else { return $binary_predicate->($values[0], $values[1]) && is_ordered_according_to($binary_predicate, @values[1..$#values]); } } sub less_than { return shift() < shift(); } print is_ordered_according_to(\&less_than, 1, 2, 3, 4, 5, 6) ? "yes" : "no", "\n" ; print is_ordered_according_to(\&less_than, 3, 2, 1, 4, 5, 6) ? "yes" : "no", "\n" ; print is_ordered_according_to(\&less_than, 1, 2, 3, 4, 6, 5) ? "yes" : "no", "\n" ;
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re^3: Why not support this syntax?
by MeowChow (Vicar) on Apr 24, 2001 at 20:12 UTC | |
|
Re: Re: Re^3: Why not support this syntax?
by scott (Chaplain) on Apr 30, 2001 at 18:13 UTC |