[plt-scheme] eq? with more than two arguments
I don't know why. But it easy to make them yoyrself.
Below a procedure and a macro version.
; Let R be a transitive relation (R x y) --> Boolean,
; accepting all x and y of some type alpha.
; Procedure: (binary->plural-relation R) --> procedure: plural relation
; Procedure: (plural-relation x y z ...) --> Boolean
; where x and y and each z is of type alpha.
; #t iff (and (R x y) (R y z[0]) (R y z[0]) ... (R y[n-1] y[n]))
(define (binary->plural-relation R)
(define (plural-relation x y . z)
(and (R x y)
(or (null? z) (apply plural-relation y z))))
plural-relation)
; Examples:
(define eqv?* (binary->plural-relation eqv?))
(eqv?* 1 1) ;--> #t
(eqv?* 1 1 1) ;--> #t
(eqv?* 1 1 1 1 1) ;--> #t
(eqv?* 1 2) ;--> #f
(eqv?* 1 1 2) ;--> #f
(eqv?* 1 1 1 1 2) ;--> #f
(eqv?* 1 1 2 3 3) ;--> #f
; (eqv?* '1) ;--> error, eqv?* wants at least two arguments.
; All arguments of eqv?* are evaluated.
; By means of a macro, evaluation of arguments whose values are not needed
; can be avoided.
(define-syntax define-plural-relation
(syntax-rules ()
((_ R* R)
(define-syntax R*
(syntax-rules ()
((_ x y) (R x y))
((_ x y z (... ...)) (and (R x y) (R* y z (... ...)))))))))
(define-plural-relation eqv?** eqv?)
; Check that 3 is not written!
(eqv?** 1 1) ;--> #t
(eqv?** 1 1 1) ;--> #t
(eqv?** 1 1 1 1 1) ;--> #t
(eqv?** 1 2 (write 3)) ;--> #f
(eqv?** 1 1 2) ;--> #f
(eqv?** 1 1 1 1 2 (write 3)) ;--> #f
(eqv?** 1 1 2 (write 3) (write 3)) ;--> #f
Jos
----- Original Message -----
From: "Doug Orleans" <dougorleans at gmail.com>
To: <plt-scheme at list.cs.brown.edu>
Sent: Saturday, April 12, 2008 9:44 PM
Subject: [plt-scheme] eq? with more than two arguments
> How come =, char=?, string=?, etc allow more than two arguments, but not
> eq?, eqv?, and equal??
>
> --dougorleans at gmail.com
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme