It's not really breaking principle of least surprise if you "expect" such functions to return sequences. A lot of people do expect this after a little bit of Lisp experience (Clojure or otherwise)
I can see two "advantages" to having many functions return seqs: - It's a shared abstraction, which dramatically helps composability - It is a decent guess at the most efficient collection to use for general-purpose coding (functional code is pretty likely to do something recursively on a list, so a sequence is the most efficient thing to return as it supports efficient non-allocating traversal) My main issue with it is that (currently) it often leads to the production of an intermediate sequence that isn't needed. Reducers mitigate this somewhat in 1.5, but in the medium term I hope that the compiler gets smart enough to eliminate these. Right now it's a pain having to hand-write functions to avoid this in performance critical code, but you have to do it since the cost can be a 2x-5x overhead. On Tuesday, 2 July 2013 09:45:45 UTC+1, Islon Scherer wrote: > > One things that always bugged me about clojure is that most functions that > work on collections return seqs and not the original data structure type: > > (= [2 4 6] (-> [2 [4]] flatten (conj 6))) > => false > > Every time I transform collections I need to be aware of this. > My questions is: is there a philosophical reason for that or it was > implement this way because it's easier? Why conj is different? > Doesn't it break the principle of least surprise? > > Thanks, > Islon > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.