Clause
← All documentation

Native records

The OTP 29 record forms beyond ordinary tuple records: their representation, operations and errors. Tuple records are in terms.

OTP 29 marks native records experimental. Facts below come from the pinned maint-29 sources (erl_lint, erl_expand_records, v3_core, beam_core_to_ssa, erts/emulator/beam/erl_record.c, utils.c, erl_printf_term.c) and live probes on OTP 29.1.1.

Scope

All three forms beyond tuple records are implemented and share one representation:

FormSyntax
Native record, local-record #r{...}., #r{...}, X#r.f, X#r{...}, patterns, is_record/1,2,3
Qualified and imported#m:r{...}, X#m:r.f, X#m:r{...}, patterns; -export_record, -import_record
Inferred (anonymous)X#_.f, X#_{...}, pattern #_{...}

The records reflection module is provided (reflection). Not provided: term_to_binary of native records (error:notsup, external term format) and hot code upgrade.

Representation

Operations

M is the current module. All errors have class error; badrecord payloads are the offending value except failed external construction.

OperationAcceptsFailure
Local construction #r{...}Always (definition is local)Unknown field or missing value are compile errors
External construction #m:r{...} (also imported #r{...}, also #M:r)m:r defined in the batch and exported{badrecord, {m, r}}; then {badfield, {{m, r}, F}}, {novalue, {{m, r}, F}} (badfield wins)
Local access X#r.fNative record named r (module and export flag not checked, as OTP's runtime){badrecord, X}; field missing {badfield, {{Mod, r}, f}}
External access X#m:r.fModule m, name r, exported{badrecord, X}; {badfield, ...}
Anonymous access X#_.fAny native record (export not checked, as OTP's runtime){badrecord, X}; {badfield, ...}
Local update X#r{...}Module M, name r{badrecord, X}; unknown field {badfield, ...}
External update X#m:r{...}Exported, module m, name rsame
Anonymous update X#_{...}Exported or module Msame
Local pattern #r{...}Module M, name r, every listed field presentno match
External pattern #m:r{...}Module m, name r; exported when a field is listedno match
Anonymous pattern #_{...}Any native record; exported or module M when a field is listedno match

Compile-time rules

Messages follow erl_lint:

Reflection

records answers from the definition a record captured:

Printing and order

Differences kept

Display field order, == folding, external construction of unloaded modules and missing record warnings are recorded in differences.