flatten has been discussed before:

https://groups.google.com/forum/?fromgroups=#!topic/clojure/ye70iNJ73zc

See also CLJ-400, but it looks like no patch was submitted.

http://dev.clojure.org/jira/browse/CLJ-400

I think the general policy for Clojure is that the core functions of course 
should work as documented, but they do not necessarily handle undocumented edge 
cases.  So if you use the wrong kinds of arguments, the implementation does not 
have to detect your error -- it might throw or just give you non-useful 
results.  There's a trade-off among ease of implementation, performance and 
programmer friendliness.  If it's a common mistake, maybe an assertion is 
warranted.  If I remember correctly, Rich Hickey suggested that someday there 
might be an option to run a stricter version of Clojure (with lots of 
assertions) during development, and a faster version with less checking in 
production.

Regarding flatten in particular, I would like it to be faster and to do a bit 
more to help the careless programmer.  I was all set to submit a patch 
condemning the elegant but slow implementation when I noticed that the new 
"reducers" version of flatten in 1.5 alphas is amazingly fast.  So that looks 
like the way to go.



On Aug 29, 2012, at 3:47 PM, dmirylenka <daniilmirile...@gmail.com> wrote:

> Calling flatten on anything that is not 'sequential?' returns an empty 
> sequence:
> 
> (flatten 1); => () 
> (flatten "Hi"); => () 
> 
> With sets if feels somewhat strange:
> 
> (flatten #{#{:a} #{:b :c}}); => ()
> 
> For some reason I expected #{#{:a} #{:b :c}} to equal #{:a :b :c}.
> 
> Ok, the docstring says: "Takes any nested combination of sequential 
> things...", and sets are not sequential...
> 
> But then, why
> 
> (reduce + (flatten #{1 2})); => 0
> (r/reduce + (r/flatten #{1 2})); => 3 ?

-- 
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

Reply via email to