Reputation: 13
Please help me with using the DrScheme built-in function "filter".
"create a function "hello" that consumes a number 'Max', and a list of numbers 'L', produce a list of numbers in 'L' that are smaller than 'Max'."
edit Taken from the comments for formatting
this is what i have so far
(define (smaller? n Max)
(cond
[(> Max n) n]
[else empty]))
(define (hello Max L)
(filter smaller? L))
I don't know how to implement Max into the function hello.
Upvotes: 1
Views: 537
Reputation: 4159
Using your smaller?
definition, I would go for something like
(define (hello Max L)
(filter (lambda (n) (smaller? n Max)) L))
This uses a lambda function which is a closure over the Max argument to the hello function. So it "embeds" Max
inside the lambda function used for filtering.
Upvotes: 1
Reputation: 51561
Hint: You can create an anonymous function with lambda
:
(lambda (x) (have-fun-with x))
edit: Another hint: (> Max n)
already returns a boolean, you don't need an enclosing cond
structure.
Upvotes: 0