Question: This function is written for you | # ( define ( replace - all - tail lst id with ) ( replace - all -

This function is written for you
|#
(define (replace-all-tail lst id with)
(replace-all-helper lst id with '()))
#|
(replace-all-helper lst id with acc)-> list?
lst: list?
A list of values
id: symbol?
A value to be replaced in the list
with: symbol?
A value that will take the place of `id` in `lst`
acc: list?
An accumulator
Helper function to replace-all-tail.
|#
(define/match (replace-all-helper lst id with acc)
[('() id with acc)'()]
; ... you may need more patterns ...
[((cons first rest) id with acc)(if (equal? first id)(replace-all-helper rest id with (list acc with))(replace-all-helper rest id with (list acc first)))]
)
(module+ test
(test-equal? "replace-all: empty list"
(replace-all '()'a 'b)
'())
(test-equal? "replace-all: some replacement"
(replace-all '(b a c a)'a 'b)
'(b b c b))
replace-all-tail: some replacement
. FAILURE
name: check-equal?
location: w02lab.rkt:97:2
actual: '()
expected: '(b b c b)
why is the code failing the second test

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!