0

我有一个函数 remove_duplicates 删除列表中的重复项并返回新列表。

(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))))

))

我想将此函数调用的返回值分配给另一个函数 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))
)

任何帮助表示赞赏,谢谢!

4

1 回答 1

2

这是使用的正确语法let

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

另请注意,命名list参数和/或变量是一个坏主意,这会与同名的内置过程发生冲突。

于 2016-04-04T23:51:41.007 回答