Keys from literal maps aren't sorted; you need a sorted map.

user=> (keys {:z 1 :f 2 :a 0})
(:z :a :f)
user=> (keys (sorted-map :z 1 :f 2 :a 0))
(:a :f :z)

On May 3, 4:08 am, David Jagoe <davidja...@gmail.com> wrote:
> Hey everyone,
>
> I'm busy implementing a macro whose usage looks like this:
>
> (defentity Person
>   {:name      {:type String :validator name-validator}
>    :id-number {:type String :validator id-number-validator}
>    :height    {:type Float  :default 0.0}
>    :weight    {:type Float  :default 0.0}
>    :bmi       {:type Float  :internal true}})
>
> The macro generates a defrecord like so:
>
> (defrecord Person [name id-number height weight bmi])
>
> Which can later be used in the application like this:
>
> (Person. "David" "123" 1 2 3)
>
> Obviously the argument order is important. So my question is:
>
> Can I rely on (keys some-literal-map) always returning the keys in the
> order they were defined in the literal map? In my experiment, a map
> literal will create a PersistentArrayMap which I understand has sorted
> keys. Can someone confirm that this is reliable (e.g. across
> implementations?)
>
> Thanks!
> David

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