[erlang-questions] The compiler "eats" structures which are not separated by commas

Vlad Dumitrescu <>
Sun Apr 22 21:04:13 CEST 2012

On Sun, Apr 22, 2012 at 19:57, Matthew Evans <> wrote:
> One thing that would be nice is given:
> -record(foo, {a = 1, b = 2}).
> t() ->
>   Foo = #foo{a = 8, b = 7},
>   Foo#foo.a.
> That since the pre-processor has seen that Foo is bound to a record #foo
> that I could do this instead:
> t() ->
>   Foo = #foo{a = 8, b = 7},
>   Foo.a.

That would have to be the compiler's job, not the preprocessor's. And
then it could help even in the following cases:
    t(X=#foo{}) -> X.a.
    t(X) when is_record(X, foo) -> X.a.

Now, this gets me even more off-topic, but its' still related... What
if the compiler would do some simple static typing analysis and also
warn for things like
    f(X) when is_atom(X) -> X+1.
    f(X) -> X = hello, X+1.
    f(X) when is_integer(X) -> X+1.
    g() -> f(hello).
? Some of this information is already easily accessible and the rest
doesn't feel like too difficult to retrieve, so I don't think it is a
too far-fetched suggestion.


More information about the erlang-questions mailing list