All about types. The sequence functions act the way they call seq on their argument and therefore do not always return the same type of object. Collection functions and type-specific functions do not call seq and return an object of the same type as what was given to them. This makes them an illusion of returning the same object (this may be the reason for this behavior), even if it really is not. We can say that the rule of thumb is that functions preserve meta while preserving type.
user> (meta (seq (with-meta (list 1) {:a 1}))) {:a 1} user> (meta (seq (with-meta (vector 1) {:a 1}))) nil
Be sure to remember when laziness was tough:
user> (type (list 1)) clojure.lang.PersistentList user> (type (map identity (list 1))) clojure.lang.LazySeq user> (meta (seq (with-meta (map identity (list 1)) {:a 1}))) nil
For a list of functions storing meta on collection, see the data structure section. Those that don't save the meta are on the sequences page, except when they return an object of the same type.
Under the hood, I'm not quite sure of the details, as a sequence of laziness and chunked has been added, but you can look at the cons , seq and seqFrom from the RT class. These methods perform functions that do not store metadata. For now, collection functions end using methods specific to their types.
Nicolas buduroi
source share