Hello,
This example showed up on the Perl 6 mailing list:
if any(@new_values) > all(@existing_values) {
$upper_limit = [max] @new_values;
}
Let's just take the comparison, which is using the fancy Perl 6 junctions:
any(@new_values) > all(@existing_values)
OK, using any and every from SRFI 1, heres that comparison:
(any (lambda (new-value)
(every (lambda (existing-value)
(> new-value existing-value))
existing-values))
new-values)
The verbosity is partly due to the explicit lambdas. Ya gotta get
higher order on this guy.
I employed the arbitrary order 'curry' macro I shared yesterday to name
some reusable variants of 'every':
(define every-of (curry every b a))
(define every-is (curry every a b))
and 'any':
(define any-of (curry any b a))
(define any-are (curry any a b))
I also mentioned that I have some basic math procedures like
'subtract-from' and 'divide-by'. In that list I had
'greater-than':
(define greater-than (curry > b a))
Here is 'greater':
(define greater (curry > a b))
I'll need a way to compose procedures. I'm going to use 'uni' from my
concatenative combinators library:
(define (uni f c)
(lambda (x)
(c (f x))))
OK, given these nice, reusable, named abstractions, an expression of
the original Perl 6 comparison is:
( (any-of new-values) (uni greater (every-of existing-values)) )
Ed