[racket] arity of + versus <=

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Fri Oct 28 13:58:06 EDT 2011

On Oct 28, 2011, at 1:23 PM, Joe Marshall wrote:

> On the other hand, providing code to demonstrate a particular way
> of generalizing may carry more weight than a simple assertion of
> incorrectness.  But I could be wrong here as well.

OK, here's a variant of "binary->nary" that produces the results we want when "op" has contract "X X -> boolean" rather than "X X -> X"

(define (binary->nary relop)
   (letrec ((f (lambda args
                 (or (empty? args)
                     (empty? (rest args))
                     (and (relop (first args) (second args))
                          (apply f (rest args)))))))
     f))

This applies relop to each successive (overlapping) pair of elements and "and"s the results.


Stephen Bloch
sbloch at adelphi.edu




Posted on the users mailing list.