[racket] arity of + versus <=

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Fri Oct 28 13:01:52 EDT 2011

To John:
  The original poster was asking why the comparison operators do not generalize
downward to 1-ary and 0-ary versions.  Upward generalization works.

On Fri, Oct 28, 2011 at 9:31 AM, Arthur Nunes-Harwitt <anh at cs.rit.edu> wrote:
> Hi,
>  That's the wrong question.

Well, sort of.

>  Recall that (= x1 x2 x3 ... xn) means
> (x1 = x2) & (x2 = x3) & ... & (xn-1 = xn).

Yes, but I was generalizing in a different way:

(define (binary-add a b) (+ a b))
(define (binary-multiply a b) (* a b))

(define (binary->nary op base-case)
  (lambda args (fold-left op base-case args))) ; *****

(define add (binary->nary binary-add 0))
(define multiply (binary->nary binary-multiply 1))

(The line with asterisks is because it is not specified whether OP is
left-associative or right-associative.  Fortunately, add and multiply work
both ways.)


Posted on the users mailing list.