;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname tail_recursion_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "2htdp"))))) ;; parity : list-of-boolean -> boolean ;; returns true if there are an even number of booleans, and false otherwise (define (parity l) (cond [(empty? l) true] [else (xor (first l) (parity (rest l)))])) ;; xor : boolean boolean -> boolean (define (xor b1 b2) (or (and b2 (not b1)) (and b1 (not b2)))) (check-expect (parity (list false true false false)) false) (check-expect (parity2 (list false true false false)) false) (define (parity2 l) (parity/acc l true)) (define (parity/acc l acc) (cond [(empty? l) acc] [else (parity/acc (rest l) (xor (first l) acc))]))