Hi Pablo,
I think you're right. Have a look at flatten source
(defn flatten
"Takes any nested combination of sequential things (lists, vectors,
etc.) and returns their contents as a single, flat sequence.
(flatten nil) returns an empty sequence."
{:added "1.2"
:static true}
[x]
(filter (complement sequential?)
(rest (tree-seq sequential? seq x))))
it is the rest function that causes this behavior and it seems to be just
an optimization to avoid filtering the first element of tree-seq that is
known to be the whole sequence. A simpler definition of flatten seems to
have the behavior you expected.
(defn flatten1 [x] (filter (complement sequential?) (tree-seq sequential?
seq x)))
Il giorno mercoledì 1 luglio 2015 13:55:28 UTC+2, J. Pablo Fernández ha
scritto:
>
> Hello Clojurists,
>
> Today I was surprised by the result of (flatten 1) which is '(). I was
> expecting '(1) or an error. Talking in some other people in #clojure @
> clojurians.net, not everybody agrees that '(1) is a good result but that
> '() is somewhat surprising. Would it be better if it raised an error when
> the attribute is not sequential?
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.