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
In reply to Re: Re^3: Why not support this syntax?
by clemburg
in thread Why not support this syntax?
by MeowChow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |