Skip to content

Commit d9429e7

Browse files
committed
Update reference manual about relaxed record name quoting
1 parent 7af6208 commit d9429e7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

system/doc/reference_manual/ref_man_records.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ used.
3939
FieldN [= ExprN]}).
4040
```
4141

42+
> #### Change {: .info }
43+
>
44+
> Since OTP 28.0 the record creation syntax is allowed when defining a record:
45+
> ```erlang
46+
> -record #Name{Field1 [= Expr1],
47+
> ...
48+
> FieldN [= ExprN]}).
49+
> ```
50+
4251
The default value for a field is an arbitrary expression, except that it must
4352
not use any variables.
4453
@@ -230,3 +239,39 @@ record_info(size, Record) -> Size
230239

231240
`Size` is the size of the tuple representation, that is, one more than the
232241
number of fields.
242+
243+
## Record name quoting
244+
245+
A record name is an atom. Atoms can be quoted.
246+
[Reserved words](reference_manual.md#reserved-words) and variable
247+
names are not atoms, unless quoted.
248+
249+
For example `div` is the integer division operator so it cannot be used
250+
as a record name unless quoted:
251+
252+
``` erlang
253+
-record('div', {field :: integer()}).
254+
255+
foo() -> #'div'{field = 17}.
256+
```
257+
258+
The same applies to a variable name such as `Var`:
259+
260+
``` erlang
261+
-record('Var', {field :: integer()}).
262+
263+
foo() -> #'Var'{field = 4711}.
264+
```
265+
266+
> #### Change {: .info }
267+
>
268+
> Since OTP-28.0, a name after the `#` operator doesn't have to be quoted,
269+
> and since record definition can be done with record creation syntax,
270+
> this also works:
271+
> ``` erlang
272+
> -record #div{field :: integer()}).
273+
> -record #Var{field :: integer()}).
274+
>
275+
> foo() -> #div{field = 17}.
276+
> bar() -> #Var{field = 4711}.
277+
> ```

0 commit comments

Comments
 (0)