Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created May 4, 2010 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Licenser/390080 to your computer and use it in GitHub Desktop.
Save Licenser/390080 to your computer and use it in GitHub Desktop.
(defn and-seq
([e]
(list e))
([e & es]
(letfn [
(and-seq* ([e] (list "and" e))
([e & es] (lazy-seq (concat (list "," e) (apply and-seq* es)))))]
(conj (apply and-seq* es) e))))
(defn and-seq
([e] (list e))
([e & es]
(letfn [(and-seq* [e]
(let [[f & r] e]
(if r
(lazy-seq (concat (list "," f) (and-seq* r)))
(list "and" f))))]
(conj (and-seq* es) e))))
(defn combiner
([m] (combiner m m))
([m l]
(fn
([e] (list e))
([e & es]
(letfn [(and-seq* [e]
(let [[f & r] e]
(if r
(lazy-seq (concat (list m f) (and-seq* r)))
(list l f))))]
(conj (and-seq* es) e))))))
((combiner "," "and") 1 2 3)
(apply str ((combiner ", " " and ") 1 2 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment