0

I have a function remove_duplicates that removes the duplicates in a list and returns the new list.

(define (remove_duplicate list)
(cond
    ((null? list) '() )

    ;member? returns #t if the element is in the list and #f otherwise
    ((member? (car list) (cdr list)) (remove_duplicate(cdr list)))

    (else (cons (car list) (remove_duplicate (cdr list))))

))

I want to assign the return value from this function call to a variable in another function f.

(define (f list)
    ;I have tried this syntax and various other things without getting the results I would like
    (let* (list) (remove_duplicates list))
)

Any help is appreciated, thanks!

CS student
  • 305
  • 1
  • 3
  • 13

1 Answers1

2

This is the correct syntax for using let:

(define (f lst)
  (let ((list-without-dups (remove_duplicates lst)))
    ; here you can use the variable called list-without-dups
    ))

Also notice that it's a bad idea to name list a parameter and/or a variable, that clashes with a built-in procedure with the same name.

Óscar López
  • 232,561
  • 37
  • 312
  • 386