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

Jan Burse <>
Sat Apr 21 23:04:55 CEST 2012


Vlad Dumitrescu schrieb:
>>>> The compiler "eats" structures which are not separated by commas.
>>>> start() ->
>>>>      [
>>>>       #haha{v=1}   %% No comma here
>>>>       #haha{v=2}   %% No comma here
>>>>       #haha{v=3}
>>>>      ].
>>>
>>> No, the code is equivalent to ((#haha{v=1})#haha{v=2})#haha{v=3}.

Maybe adopt some technique from La La Land:

Step I:

- Distinguish constructor and setter, instead of

      Constructor: #Name{Field1=Expr1,...}
      Setter: Expr#Name{Field1=Expr1,...}
      Getter: Expr#Name.Field

   Use different syntactic forms, i.e. for example:

      Constructur: #Name{Field1=Expr1,...}
      Setter: Expr #setName{Field1=Expr1,...}
      Getter: Expr #getName.Field

Step II

- Use type inference, to deduce the record typ, instead of

      Constructur: #Name{Field1=Expr1,...}
      Setter: Expr #setName{Field1=Expr1,...}
      Getter: Expr #getName.Field

   One can use the abbreviated forms:

      Constructur: #Name{Field1=Expr1,...}
      Setter: Expr #set{Field1=Expr1,...}
      Getter: Expr #get.Field

   Or maybe even better:

      Constructur: #Name{Field1=Expr1,...}
      Setter: Expr #setField(Expr1) #...
      Getter: Expr #getField()

Actually I don't know if a sufficient type inference
could be realized for Erlang so that the above
would work.

Bye




More information about the erlang-questions mailing list