Skip to content

Instantly share code, notes, and snippets.

@alexpw
Created October 28, 2014 17:16
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 alexpw/3da61dc17360b350327b to your computer and use it in GitHub Desktop.
Save alexpw/3da61dc17360b350327b to your computer and use it in GitHub Desktop.
pfds 2.1 suffixes sml
(defn suffixes
"Recursive suffixes"
[xs]
(if-let [xs (seq xs)]
(cons xs (suffixes (rest xs)))
[()]))
(defn suffixes
"Tail-recursive suffixes"
[xs]
(letfn [(f [xs rs]
(if (seq xs)
(recur (rest xs) (conj rs xs))
(conj rs [])))]
(f xs [])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment