I am sorry, You are correct. I see what you mean. I mis-interpreted meta()
as returning an empty meta-map.
On Sunday, July 29, 2012 10:26:46 AM UTC+2, Per Mildner wrote:
>
> Thanks, but the question was not about the empty() methods.
>
> On Sunday, July 29, 2012 4:14:09 AM UTC+2, tbc++ wrote:
>>
>>
>>
>> On Sat, Jul 28, 2012 at 7:47 AM, Per Mildner wrote:
>>
>>> Looking at the persistent types in clojure.lang.*
>>> (PersistentVector.java et al.) I see several occurrences of the
>>> idiom EMPTY.withMeta(meta()) where EMPTY is a constant (static final)
>>> denoting an empty collection of the appropriate type.
>>>
>>> What I can not understand, given that these types are all persistent, is
>>> why the EMPTY constant is, in effect, copied at most places where it is
>>> used. Why not use the same EMPTY instance instead, i.e.
>>> replace EMPTY.withMeta(meta()) with just EMPTY. Unless I miss something
>>> this could not hurt and would save some time and space.
>>>
>>>
>> In this context, the empty() method does not mean "get an empty of this
>> type", instead it means "empty this collection". So if we want to return a
>> new collection that looks the same, except it is empty, then we need to
>> pull in the metadata from the old collection.
>>
>> Example:
>>
>> => (meta (empty (with-meta [1 2 3] {:foo true})))
>> {:foo true}
>>
>>
>> Timothy
>>
>
--
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