We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our design goal, we hope to make it simple to upgrade most tuple records to native records. That is why native records use the same syntax as the existing tuple records except in declaration.
Our plan is to include native records in RC1 of OTP 29. In the later RCs of OTP 29, we will add support for native records to more applications, like syntax tools and Dialyzer. By OTP 30, we will add performance improvements and broader support for tools, as described in the EEP.
Overall, looks good and interesting. It looks to be useful for gen_* states. I find it slightly confusing that non-exported record types can be still used outside the module, but I guess this is unavoidable as data can leave the module in various ways.
I was wondering, do we really need the underscore for anonymous access and update? I mean in the
Expr#_.Field
expression the three consecutive punctuation mark characters are approaching “line noise territory”. Would using the same syntax as the tuple-records lead to slightly worse performance? I mean the runtime would know the type of Expr at this point and based on the type the runtime would know how to access Field.
I haven’t looked at the Erlang parser, but is it that difficult to extend the -import attribute to support these native records? Then we can have something like this?
Also, why can’t the -record(...) attribute be upgraded to allow the definition of native records?
% Old
-record(person, {name, age}).
% New
-record(#person, {name, age})
There are so many new attributes and inconsistencies introduced or about to be introduced lately:
new -import_type attribute
new -import_record attribute
new attribute formats: -doc(“…”) OR -doc “…”, why not just -doc(“…”)?
I understanding introducing new functionality can’t always be accommodated by existing structures, but it would be nice if we could attempt. Consistency is beautiful!
A long time ago, I wanted to implement an incremental marking feature for data type modifications in Erlang to facilitate the storage or broadcasting of incremental data. However, I was never successful because I didn’t have a thorough understanding of Erlang’s parse_transform. Recently, I saw this new Native Records data type, which reminded me of what I wanted to do before. With the help of AI programming, I implemented a feature that marks the updated fields after a record update. The relevant code is available at https://github.com/ErlGameWorld/ePtDirty . I think it would be great if Native Records natively supported this incremental modification marking feature.