622 名前:デフォルトの名無しさん mailto:sage [2009/07/01(水) 14:37:48 ] schemeをさらにシンプルにしようと思って こんなのを考えてみたんだけどどう思う? consセルだけのほうが ()について非対称なリストよりもシンプル ;consセル版fold (define (cfold f a b) (cond ((not (pair? b)) (f a b)) (else (cfold f (f a (car b)) (cdr b))))) (define (cfold1 f lst) (cfold f (car lst) (cdr lst))) ;reverseがリストよりもシンプルで効率的に(appendなしで)書ける (cfold1 (lambda (x y) (cons y x)) '(1 2 . 3)) ;このままだと、「空」が表現できないので ;consを仮にこんな風に定義してみる ;()なら無視するcons (define (conss x y) (cond ((null? x) y) ((null? y) x) ;片側だけのほうがよいか? (else (cons x y)))) ;末尾に()がないと思っても良い (cfold (lambda (x y) (conss y x)) () '(1 2 . 3)) ;←これを言語レベルで'(1 2 3)と表記 (cfold (lambda (x y) (conss y x)) () '(1 2 3))