I can define a record on the erl shell via:
129> rd(person, {name=""}).
person
130> #person {}.
#person{name = []}
131> #person {name="dummy"}.
#person{name = "dummy"}
But I’m not sure how to define and use records in a module. When I create my_module.erl:
-module(my_module).
-record(person, {name, phone, address}).
#person {name="dummy"}.
…and try to compile, I get:
132> c(my_module).
my_module.erl:5: syntax error before: '#'
my_module.erl:3: Warning: record person is unused
error
The documentation says rd is used in the shell since records are available at compile time, not runtime. So I would assume I wouldn’t need to use rd in the module definition.
You have defined it right, but a record can only be used inside a function (when it’s inside a module).
So add something like
test_record() -> #person{name="dummy"}.Then you can see the results from the Erlang shell with
my_module:test_record()