Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (partition good? list return)
- (match list
- [(list)
- (return `() `())]
- [(list head tail ...)
- (partition good? tail (λ (accepted rejected)
- (if (good? head)
- (return (cons head accepted) rejected)
- (return accepted (cons head rejected)))))]))
- (partition (curry < 4) `(1 9 2 8 3 7 4 6 5) (λ (good bad)
- (printf "good: ~a; bad ~a~%" good bad)))
- (define (split-at n list return)
- (if ((zero? n) . or . (null? list))
- (return `() list)
- ; else
- (match list [(list head tail ...)
- (split-at (n . - . 1) tail
- (λ (before after)
- (return (cons head before) after)))])))
- (split-at 5 `(1 2 3 4 5 6 7 8 9) (λ (before after)
- (printf "before: ~a; after ~a~%" before after)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement