Record selectors

Daniel Dudley daniel.dudley@REDACTED
Thu Jan 2 18:50:14 CET 2003


I'm curious as to why it is necessary to specify the record
name when selecting a record instance bound to a variable,
i.e., Variable#RecordName.Field. Using an example from the
Erlang Extensions document, but following good programming
practice by using a meaningful variable name, we have:

    > Person = #person{name = "Joe", [0,8,2,3,4,3,1,2]}.
    {person, "Joe", [0,8,2,3,4,3,1,2], undefined}
    > Person#person.name.
    "Joe"

Since the Person variable is bound to an instance of person
records, it seems to me that it should be possible to use
syntax like one of the following examples to retrieve field
data (and avoid duplicity and unnecessary keyboard typing
in the code):

1)  > Person#.name
2)  > Person#name
3)  > Person.name

I venture to suggest that any of these examples are far
more readable than and just as understandable as the
original, prescribed syntax.

Would I be correct in assuming that the compiler is too
"dumb" to recognize the Person <-> person-record binding
with one of the suggested alternative syntax?

But hey, maybe I'm just missing something -- it wouldn't be
the first time! ;-)

Daniel




More information about the erlang-questions mailing list