Rewrite the following accumulator function to use foldl.
;;even-trues? : (listof booleans) -> boolean
;; to determine iflob
contains an even number oftrue
s. (define (even-trues? lob) (even-trues?/a lob true)) ;;even-trues?/a : (listof booleans) boolean -> boolean
;; the accumulator istrue
if there were an even number of ;;true
s seen so far and false if there were an odd number oftrue
s ;; seen so far. (define (even-trues?/a lob a) (cond [(empty? lob) a] [else (even-trues?/a (rest lob) (cond [(first lob) (not a)] [else a]))])) ;;foldl : (listof X) Y (X Y -> Y) -> Y
(define (foldl l a combine) (cond [(empty? l) a] [else (foldl (rest l) (combine (first l) a) combine)]))
Solution
(define (even-trues? l) (foldl l true (lambda (x y) (not (boolean=? x y)))))