Created
October 28, 2014 17:16
-
-
Save alexpw/3da61dc17360b350327b to your computer and use it in GitHub Desktop.
pfds 2.1 suffixes sml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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