Skip to content

Instantly share code, notes, and snippets.

@masaedw
Created May 8, 2010 09:09
Show Gist options
  • Save masaedw/394459 to your computer and use it in GitHub Desktop.
Save masaedw/394459 to your computer and use it in GitHub Desktop.
;; なんかうまくいかない版
(defn myflatten [lst]
(lazy-seq
(if (empty? lst) lst
(let [[x & xs] lst]
(if (seq? x)
(myconcat (myflatten x) (myflatten xs))
(cons x (myflatten xs)))))))
;; うまくいく版
(defn myflatten [lst]
(lazy-seq
(if (empty? lst) lst
(let [x (first lst)
xs (rest lst)]
(if (seq? x)
(myconcat (myflatten x) (myflatten xs))
(cons x (myflatten xs)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment