Record type is equals of hashmap (clojure)?

In hash-map - clojure.core | ClojureDocs - Community-Powered Clojure Documentation and Examples when it change it make new leaf with old struct and new changed fields. Is it right for record type when it do

{ x with someField = newValue }

?

Not exactly. A clojure hash-map is going to be structured as a tree, same as an F# Map. An F# map will indeed make a new leaf with the old struct and the new changed fields whenever you change an element.

But records are different. Since it’s a compiled language, they’re not stored in memory as mappings of string keys to values, with a tree structure to make looking up the keynames more quick. They’re more efficient than that - think of it a bit more like an array, where whenever you access a field, the compiler knows the precise index to jump to without having to match keynames. When you do an update, it will reuse all of the fields in the old struct, and just update the new fields, but it will be in a flat structure which is going to be quicker than a tree.

2 Likes