Open Source WEB

##(link2sicp "book-Z-H-16.html#%_thm_2.59" "Exercise 2.59")

解答例

(define (union-set set1 set2)
  (cond ((null? set1) set2)
        ((null? set2) set1)
        ((element-of-set? (car set1) set2)
         (union-set (cdr set1) set2))
        (else (cons (car set1) (union-set (cdr set1) set2)))))

実行例

gosh> (union-set '(0 2 4 6 8 10) '(0 3 6 9 12))
(2 4 8 10 0 3 6 9 12)

コード

##(sicp-answer-code "ex-2.59.scm")

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us