[erlang-questions] Bug ?!

Mats Cronqvist mats.cronqvist@REDACTED
Mon Oct 2 09:35:26 CEST 2006


datacompboy wrote:
> Is that a bug of compiler?
> 
> -module(a).
> -record(x, {a, b, c}).
> -export([bug/1]).
> 
> bug(X) ->
>   receive
>     {msg, X#x.a} -> ok
>   after 0 -> ok
>   end.
> 
> We got "illegal pattern" on {msg, X#x.a}.
> If we change code so:
> bug(X) ->
>   XA = X#x.a,
>   receive
>     {msg, XA} -> ok
>   after 0 -> ok
>   end.
> 
> it works. Is that bug of records compilation, or feature?!

   it's an artifact of the (rather lame) way records are implemented. (X#x.a is 
essentially a macro for element(?INDEX(a,x),X), where INDEX is the field 
position of a in x).
   so, a feature :>

   mats



More information about the erlang-questions mailing list