Rewrite the following accumulator function to use foldl.
;;even-trues? : (listof booleans) -> boolean;; to determine iflobcontains an even number oftrues. (define (even-trues? lob) (even-trues?/a lob true)) ;;even-trues?/a : (listof booleans) boolean -> boolean;; the accumulator istrueif there were an even number of ;;trues seen so far and false if there were an odd number oftrues ;; 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)))))