Matt Gushee writes:
> I guess my explanation wasn't entirely clear, but that's pretty much
> what I was already doing. I showed the equality predicate I was using,
> which tests individual values in the list with = . I think my mistake
> was in assuming that (current-test-epsilon) would apply to = in the
> test environment. I'm guessing now that that is not the case.
Ah, yes, I hadn’t understood how you were testing. You’re right that = does not
get redefined to use current-test-epsilon. Instead you would have to use your
own equality predicate that incorporates it. test defines its approx-equal? as:
(define (approx-equal? a b epsilon)
(cond
((> (abs a) (abs b))
(approx-equal? b a epsilon))
((zero? b)
(< (abs a) epsilon))
(else
(< (abs (/ (- a b) b)) epsilon))))
Which you could then add to your predicate like so:
(define (list= l1 l2)
(and (= (length l1) (length l2))
(let loop ((l1* l1) (l2* l2))
(cond
((null? l1*) #t)
((approx-equal? (car l1*) (car l2*) (current-test-epsilon))
(loop (cdr l1*) (cdr l2*)))
(else #f)))))
--
Alex
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users