Why the designers of Clojure’s reverse function decided that the returned sequence isn’t a lazy one?
Clojure embraces lazy sequences usually.
Why the designers of Clojure’s reverse function decided that the returned sequence isn’t a
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Surely it’s because by definition, in order to reverse a sequence, you have to know what’s at the other end in order to return what will become the first item in the reversed collection.
Hence, the sequence must be finite, and you’d have to evaluate it in order to use what lies at it’s end.
Addendum:
Reverse doesn’t make sense as an infinite sequence, (although it’s fair to say that infinite sequences are not always a prerequisite for laziness).
If you are about to reverse a collection, then you already have it loaded in memory; it doesn’t need to be calculated.