Why do I get the following error with lambda? (lambda: found a lambda that is not a function definition) And would there be an alternative without using lambda? (define-struct shelf [letter authors]) (define SHELF-1 (make-shelf "A" (list "Austen" "Hurston" "Angelou" "Butler" "Alvarez"))) (define SHELF-2 (make-shelf "B" (list))) (define SHELF-3 (make-shelf "C" (list "Carle" "Coates"))) ; fix-shelves: [List-of Shelves ] -> [List-of Shelves] ; Return names that don't contain the letter on the shelf name (check-expect (fix-shelves (list SHELF-1 SHELF-2 SHELF-3)) (list (make-shelf "A" (list "Hurston" "Butler")))) (check-expect (fix-shelves (list SHELF-1)) (list (make-shelf "A" (list "Hurston" "Butler")))) (define (fix-shelves lst) (cond [(empty? lst) empty] [else (append (fix-shelf (first lst)) (fix-shelves (rest lst)))])) (define (fix-shelf sh) (cond [(empty? (shelf-authors sh)) empty] [else (make-shelf (shelf-letter sh) (removes (lambda (x) (contains? (shelf-letter sh) )) (shelf-authors sh)))])) (define (contains? str char) (cond [(empty? str) false] [else (if (char=? char (first str)) #true (contains? (rest str) char))])) (define (removes pred lst) (cond [(empty? lst) empty] [(pred (first lst)) (removes pred (rest lst))] [else (list (first lst) (removes pred (rest lst)))]))
Why do I get the following error with lambda? (lambda: found a lambda that is not a function definition)
And would there be an alternative without using lambda?
(define-struct shelf [letter authors])
(define SHELF-1 (make-shelf "A" (list "Austen" "Hurston" "Angelou" "Butler" "Alvarez")))
(define SHELF-2 (make-shelf "B" (list)))
(define SHELF-3 (make-shelf "C" (list "Carle" "Coates")))
; fix-shelves: [List-of Shelves ] -> [List-of Shelves]
; Return names that don't contain the letter on the shelf name
(check-expect (fix-shelves (list SHELF-1 SHELF-2 SHELF-3))
(list (make-shelf "A" (list "Hurston" "Butler"))))
(check-expect (fix-shelves (list SHELF-1))
(list (make-shelf "A" (list "Hurston" "Butler"))))
(define (fix-shelves lst)
(cond
[(empty? lst) empty]
[else (append (fix-shelf (first lst)) (fix-shelves (rest lst)))]))
(define (fix-shelf sh)
(cond
[(empty? (shelf-authors sh)) empty]
[else (make-shelf (shelf-letter sh)
(removes (lambda (x) (contains? (shelf-letter sh) ))
(shelf-authors sh)))]))
(define (contains? str char)
(cond
[(empty? str) false]
[else (if (char=? char (first str))
#true
(contains? (rest str) char))]))
(define (removes pred lst)
(cond
[(empty? lst) empty]
[(pred (first lst)) (removes pred (rest lst))]
[else (list (first lst) (removes pred (rest lst)))]))
Step by step
Solved in 2 steps