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)))]))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)))]))

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education