Entries from 2015-02-01 to 1 month
こっちのほうがシンプルでいいような気もする。 (define (flatten lis) (cond [(null? lis) '()] [(not (list? lis)) (list lis)] [else (append (flatten (car lis)) (flatten (cdr lis)))])) 早く継続を勉強して、継続で書いてみたい。
(define (flatten list) (let loop ((list1 (reverse list)) (list2 '())) (if (null? list1) list2 (if (list? (car list1)) (loop (cdr list1) (append (flatten (car list1)) list2)) (loop (cdr list1) (cons (car list1) list2))))))
(define (any-pred . preds) (lambda (x) (fold (lambda (pred res) (or (pred x) res)) #f preds))) (define (every-pred . preds) (lambda (x) (fold (lambda (pred res) (and (pred x) res)) #t preds)))