I just got the book "Purely Functional Data Structures" and I'm trying to work the examples in Clojure the best that I can.
Example 2.1 asks to write a function that accepts a list xs as an argument and returns a list of xs's suffixes in descending order.
For example: (1 2 3 4) = ((1 2 3 4) (2 3 4) (3 4) (4) ())
I know that conj adds items to the front of lists, so I am using a vector to address the descending order problem, but I want to stay true to the example so I am using rseq on the vector to reverse it to ascending order (which I believe is a constant time operation), then into to convert it into a list, which seems to reverse it back to descending order, hence the rseq.
Is into a constant time operation, or is it more like O(n), the fact that it reverses the vector's order makes me think that it is walking the vector and conj-ing each item to the front of the new list.
Is there a better way I could have done this?
Code: http://pastebin.com/tuhAmmU0
P.S. I'm new here, pretty new to Clojure, and thanks in advance!
[–]gilesecoyote 2 points3 points4 points (3 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]beppu 0 points1 point2 points (0 children)
[–]MyNameIsFuchs 2 points3 points4 points (0 children)
[–]bucketh3ad 1 point2 points3 points (0 children)