2016-04-04 18 views
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)) 
) 

ご協力いただきありがとうございます。

答えて

2

これはletを使用するための正しい構文です:

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

はまた、同じ名前を持つ組込みプロシージャとの衝突ということ、それはパラメータおよび/または変数listに名前を付けるために悪い考えだということに気づきます。

関連する問題