Since this looks like a homework question, I'm not going to provide all the code, but hopefully push you in the right direction.
From the HTDP book, we see that "The Intermediate Student language adds local bindings and higher-order functions." The trick here is probably going to using "local bindings".
Some assumptions:
(remove-min-from-list '()) => not allowed: input list must be non-empty
(remove-min-from-list '(1)) => '()
(remove-min-from-list '(1 2 3 1 2 3)) => '(2 3 2 3) ; all instances of 1 were removed
Somehow, we need to find the minimum value of the list. Call this function min-of-list
. What are its inputs and outputs? It's input is a list of numbers and its output is a number. Of the abstract list functions, which ones allow us to turn a list of numbers into a number? (And not another list.) This looks like foldl
/foldr
to me.
(define (min-of-list lst)
(foldr some-function some-base lst))
Since you already showed that you could write min-of-list
recursively, let's move on. See @WorBlux's answer for hints there.
How would we use this in our next function remove-min-from-list
? What are the inputs and outputs of remove-min-from-list
? It takes a list of numbers and returns a list of numbers. Okay, that looks like map
or filter
. However, the input list is potentially shorter than that output list, so filter
and not map
.
(define (remove-min-from-list lst)
....
(filter some-predicate list))
What does some-predicate
look like? It needs to return #f
for the minimum value of the list.
Let's pull this all together and use local
to write one function:
(define (remove-min-from-list lst)
(local [(define min-value ...)
(define (should-stay-in-list? number) ...min-value ...)]
(filter should-stay-in-list? lst)))
The key here, is that the definition for should-stay-in-list?
can refer to min-value
because min-value
came before it in the local
definitions block and that the filter
later on can use should-stay-in-list?
because it is in the body of the local
.