最初のページ 戻る 次へ 最後のページ

append関数とrev関数の違い

append関数とrev関数は似ているが

cons関数を評価するタイミングが違う

(define (rev x z)

(cond ((null? x) z)

(else (rev (cdr x) (cons (car x) z)))))

(define (append x z)

(cond ((null? x) z)

(else (cons (car x) (append (cdr x) z))) ))

巻き取り段階で新しいappendを駆動

consは巻き戻し段階で評価

revは末端再帰関数

rev中のconsは巻き取り段階で評価