hash literal oddity?

10 views
Skip to first unread message

Stuart Halloway

unread,
Jan 18, 2010, 9:46:18 PM1/18/10
to clo...@googlegroups.com
Is this expected behavior?

{1 "this" 1 "is" 1 "strange"}
=> {1 "this", 1 "is", 1 "strange"}

(into {} {1 "this" 1 "is" 1 "strange"})
=> {1 "strange"}

{1 "this" 1 "is" 1 "strange" 1 "but" 1 "if" 1 "I" 1 "try" 1 "hard" 1
"enough"}
=> {1 "enough"}

Stu


Kevin Downey

unread,
Jan 18, 2010, 10:17:38 PM1/18/10
to clo...@googlegroups.com
what you are seeing is the transition from arraymap to hashmap

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

Fogus

unread,
Jan 18, 2010, 10:27:06 PM1/18/10
to Clojure
> => {1 "this", 1 "is", 1 "strange"}

The literal representation is just blasted into an array map when the
number of entries are below a certain threshold (8 maybe). I think
the general view is that a literal with duplicate keys is the error
and to check for dups would sacrifice speed.

> (into {} {1 "this" 1 "is" 1 "strange"})

This uses a regular hash map.

> {1 "this" 1 "is" 1 "strange" 1 "but" 1 "if" 1 "I" 1 "try" 1 "hard" 1  "enough"}

I guess the threshold is indeed 8.

-m

ataggart

unread,
Jan 18, 2010, 10:29:55 PM1/18/10
to Clojure

On Jan 18, 6:46 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> Is this expected behavior?
>
> {1 "this" 1 "is" 1 "strange"}
> => {1 "this", 1 "is", 1 "strange"}

This can only happen with literal maps containing 8 or fewer entries.
Rich has commented on it elsewhere.

Fogus

unread,
Jan 18, 2010, 10:36:06 PM1/18/10
to Clojure
> This uses a regular hash map.

No it doesn't apparently... it uses conj instead.

-m

Stuart Halloway

unread,
Jan 18, 2010, 11:04:20 PM1/18/10
to clo...@googlegroups.com
>> => {1 "this", 1 "is", 1 "strange"}
>
> The literal representation is just blasted into an array map when the
> number of entries are below a certain threshold (8 maybe). I think
> the general view is that a literal with duplicate keys is the error
> and to check for dups would sacrifice speed.

The first part I knew, just wanted to verify that the second part was
expected. Thanks!

Stu

Timothy Pratley

unread,
Jan 18, 2010, 11:22:06 PM1/18/10
to clo...@googlegroups.com
Here is the previous discussion about duplicate keys in arraymaps, just for reference:
http://groups.google.com/group/clojure/browse_thread/thread/5a38a6b61b09e025

Reply all
Reply to author
Forward
0 new messages