Question: Use DrRacket Implement the following list manipulation procedures. You may find some of them useful in later exercises. Note that for accumulate, the two parameters

Use DrRacket

Implement the following list manipulation procedures. You may find some of them useful in later exercises.

Note that for accumulate, the two parameters in the lamdba represent the first item of the list, and the result of accumulate applied to the rest of the list. So, something like (lambda (x y)... might instead be better named as something like (lambda (first-of-lst result-of-rest)...

The procedure (remove object list) returns the list with all occurences of the object removed. Implement two versions: one recursive, and one without recursion using accumulate. In the former, the returned list should have the same structure as the original one with just the object removed. In this version, cons will be used to keep an item in the list (with remove called recursively on the rest of the list), otherwise to remove an item, remove will be called recursively on the rest of the list.

Accumulate hint 1:

(define (remove object list) (accumulate (lambda (item rest) ...) ... ...) 

Accumulate hint 2 (this code is very close but doesn't remove anything... just reforms the list. The lambda will require a cond):

(define (remove object list) (accumulate (lambda (item rest) (cons item rest)) null list)) 

Example:

(remove 2 (list 1 2 3 2 1)) ;Value: (1 3 1) (let ((lst (list 1 2 3))) (and (equal? (list 1 3) (remove 2 lst)) (equal? lst (remove 4 lst)))) ;Value: #t

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 Databases Questions!