# HG changeset patch # User Linus Björnstam # Date 1627848853 -7200 # Sun Aug 01 22:14:13 2021 +0200 # Node ID ba78713c0aa35f76d6cd7fa110bb7fe9302a225b # Parent c5750a43140212a6224d5201ae664c382ec402ea Added a list flattening procedure diff --git a/flatten.scm b/flatten.scm new file mode 100644 --- /dev/null +++ b/flatten.scm @@ -0,0 +1,8 @@ +;; Public domain code. Or CC0 if your jurisdiction doesn't have the notion of PD. + +(define (flatten lst) + (let loop ((lst lst) (acc '())) + (cond + ((null? lst) acc) + ((pair? lst) (loop (car lst) (loop (cdr lst) acc))) + (else (cons lst acc)))))