Advertisement
Guest User

flatten in scheme

a guest
Nov 18th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.33 KB | None | 0 0
  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)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement