On May 3, 2011, at 7:08 AM, David Jagoe wrote: > Can I rely on (keys some-literal-map) always returning the keys in the > order they were defined in the literal map?
In general, the key order is not guaranteed, but an array-map will maintain the insertion order of the keys. Use the array-map function to create one. There's a bit more info here: http://clojuredocs.org/clojure_core/clojure.core/array-map > An array-map maintains the insertion order of the keys. Look up is linear, > which is not a problem for small maps (say less than 10 keys). If your map is > large, you should use hash-map instead. > > When you assoc onto an existing array-map, the result is a new array-map with > the new key as the first key. The rest of the keys are in the same order as > the original. Functions such as seq and keys will respect the key order. > > Note that assoc will decide to return a hash-map if the result is too big to > be efficient. For your specific purpose, I would be careful about using a map as an "entity" specification. If the order is significant, a vector of field specifiers would be better. Instead of taking a map as the second argument to defentity, you could make it variadic like (defmacro defentity [ent & specs] ...). -- 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