Erlang Records Cheatsheet
I hate looking stuff up. I just like having this type of thing 1 click away, in a nice summary. This post is mostly for me.
Define a record:
-record( rule, {ruleid, site, rule, original} ).
You can define a record in the shell using rd:
99> rd(rule, {ruleid, site, rule, original} ). rule
Create an instance of a record:
100> A = #rule{ ruleid=1, site=2, rule=2, original=3}. #rule{ruleid = 1,site = 2,rule = 2,original = 3}
Access a single field in a record:
101> A#rule.original. 3
Extracting multiple fields:
102> #rule{ruleid=B, site=C, rule=D, original=E} = A. #rule{ruleid = 1,site = 2,rule = 2,original = 3} 103> B. 1 104> C. 2 105> D. 2 106> E. 3
Recommended Reading Introduction to Records
If you found this post helpful, please consider sharing to your network. I'm also available to help you be successful with your distributed systems! Please reach out if you're interested in working with me, and I'll be happy to schedule a free one-hour consultation.