Does Erlang record name allow period inside the name?

A coworker of mine wanted to use an Erlang record name with a period inside, such as:


(Note that quotes are required to show that the is an atom.)

Is this possible? Or is this prohibited?

I suggested the coworker to avoid using this confusing naming, but I’m curious if this is technically possible.



FYI: this code compiled with no error and worked OK.



        {foo = 0,
         bar = 1}).

test() ->
        V1 = #''{foo = 100, bar = 200},

test2(#''{foo = Vfoo, bar = Vbar}) ->
        io:format("foo = ~p, bar = ~p~n", [Vfoo, Vbar]).

Execution result:

Erlang/OTP 25 [erts-13.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns] [dtrace] [sharing-preserving]

Eshell V13.1  (abort with ^G)
1> l(record_period).
2> record_period:test().
foo = 100, bar = 200
1 Like

The only requirement is that the record name is a valid atom, which in this case it is though it has to be quoted. The same applies to the keynames in a record, they have to be valid atoms. So the following is a perfectly legal record:

-record('Stuff.Data',{'Data.Field1', 'Data.Field2'}).

I have seen record and field names like this in Ericsson code.

Btw these are the same rules as for function and module names, they have to be valid atoms.


If I not mistake, Elixir does this a lot, for example, a module Namespace.MyModule will became ‘Namespace.MyModule’ and a function myfun! wil be ‘myfun!’.


Yes, but that is because Elixir has a bit more complex syntax with special case handling of module names and atoms. So atoms can END in ! or ? without any need for quoting and names STARTING with an uppercase are module names which apart from the “normal” atom syntax also can contain .. Note that module names actually expand to an atom prefixed by Elixir. so the Foo.Bar ==> Elixir.Foo.Bar. This makes it much easier to have a “separate” Elixir module namespace as all module names must be atoms.


Robert, I’m very much appreciated for the clarification. I’ll tell the coworker that he’s doing the right thing :slight_smile: