flatten in scheme
a guest Nov 18th, 2019 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- ;; Here ya go. This is flatten in scheme.
- ;; Has a nasty little thing in that it flattens improper lists to proper lists
- ;; but at least it won't die.
- (define (flatten lst)
- (let loop ((lst lst) (acc '()))
- ((null? lst) acc)
- ((pair? lst) (loop (car lst) (loop (cdr lst) acc)))
- (else (cons lst acc)))))
RAW Paste Data