SHARE
TWEET

flatten in scheme

a guest Nov 18th, 2019 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; Here ya go. This is flatten in scheme.
  2. ;; Has a nasty little thing in that it flattens improper lists to proper lists
  3. ;; but at least it won't die.
  4. (define (flatten lst)
  5.   (let loop ((lst lst) (acc '()))
  6.     (cond
  7.      ((null? lst) acc)
  8.      ((pair? lst) (loop (car lst) (loop (cdr lst) acc)))
  9.      (else (cons lst acc)))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top