Comment detail

アレイのuniq (Nested Flatten)

This comment is reply for 465 es: #457や#462を思いつけるようになりたい。(アレイのuniq). Go to thread root.

リストの処理で、foldを使うのならこういうのも。最後にreverseするのが残念な感じですが。!無しで。
1
2
3
4
5
6
(define (uniq a)
  (reverse
    (fold (lambda (e knil)
            (if (member e knil)
              knil
              (cons e knil))) () a)))
毎回 (null? l) する無駄や (append l (list e)) あたりの汚さが
消えてすっきりキレイに!
なるほど納得。ありがとうございます。

Index

Feed

Other

Link

Pathtraq

loading...