Erlang / Erlang Advanced Interview questions
What are Erlang maps and how do they differ from records?
A map is a dynamic key-value data structure, written #{Key => Value}, where keys can be
any term and the set of keys is decided at runtime rather than fixed at compile time. A record is
syntactic sugar over a tuple with a fixed, compile-time-known set of named fields.
M = #{name => "Ada", age => 34}, Age = maps:get(age, M), M2 = M#{age => 35}. %% functional update, returns a new map
| Record | Map |
| Fixed fields, known at compile time; compiles to a plain tuple. | Dynamic keys, can vary at runtime; a distinct built-in data type. |
| Field access requires the record definition to be in scope. | Keys/values are directly inspectable without any compile-time definition. |
| Best for fixed-shape internal data (like OTP state). | Best for flexible, JSON-like, or externally-driven data. |
More Related questions...