[plt-scheme] Check for function equality?

From: dave yrueta (dyrueta at gmail.com)
Date: Thu Feb 19 16:43:30 EST 2009

Hi All --

Is there a Scheme function similar to "check-expect" that tests for
equality between functions?

Example:

;23.3.2
;g-fives-closed : N -> number
;non-recursive version of g-fives
;(check-expect (g-fives-closed 3) 375)
(define (g-fives-closed n)
  (* 3 (expt 5 n)))

;23.3.4
;geometric-series : number number -> (number -> number)
;consumes two numbers start and s, produces a function representing
the geometric series whose starting point is start and whose factor is
s
(define (geometric-series start s)
  (local ((define (local-g-series n)
            (* start (expt s n))))
    local-g-series))

(define g-fives-closed-test (geometric-series 3 5))

;test 1 = test passes
(check-expect (g-fives-closed-test 3) (g-fives-closed 3))

;test 2 = test fails
(check-expect g-fives-closed-test g-fives-closed)

As far as I can tell, "g-fives-closed-test" and "g-fives-closed"
differ in name only. I ran the same test with eq? and equal? and
received the same results.  Any way to test for this kind of equality?

Thanks,
Dave Yrueta


Posted on the users mailing list.