I saw the following example in Rich video on http://blip.tv/file/734409 sequences for about 33-36 minutes:
(first "abcd") => \a
Now he says that it expands to (view):
(first "abcd") => (first (seq "abcd")) => (first '(\a \b \c \d))
Thus, it looks like an O(N) operation because a full copy of the string is being executed. First of all, if a String is immutable, then why is it copied? (Edit: based on the answer, it probably is not, just looked at this path when printing.) Secondly, suppose that first operates on something else in Java, which is modified, for example, a linked list of integers. Should first act in a lazy way (e.g. create a constant sequence first)? Doesn't it make sense to evaluate it right away and save it? It would be some kind of hack that would break a good abstraction, but, I think, quickly do this work. When you call (seq "abcd") , you do not know how it will be used. When you call first on seq , you know what to do. But, when you call first on "abcd" , I think that doing hacker and quick "captures and saving" approaches is better than capturing a sequence and then calling first .
Am I missing something? Did Rick Hickey skip a few steps?
Let me know if I have any questions. Thanks!
performance clojure
Hamish grubijan
source share