[erlang-questions] Bug ?!
Valentin Micic
valentin@REDACTED
Mon Oct 2 10:08:30 CEST 2006
No, this is not a compiler bug. One cannot use record accessor syntax for
pattern matching. If you're interested in field "a" of the record "x", you
could rewrite the whole thing like this:
bug( X = #x{a=ValueOfA}) ->
receive
{msg, ValueOfA} -> ok
after 0 -> also_ok
end.
or, since X hasn't been referenced anywhere:
bug( #x{a=ValueOfA}) ->
receive
{msg, ValueOfA} -> ok
after 0 -> also_ok
end.
The above mathces the function head to a record #x{} and then binds the
complete record to variable X, and value of "a" to ValueOfA.
As for receive statement, one can also use record syntax in pattern matching
i.e.:
bug( _ ) ->
receive
{msg, X = #x{}} -> ok
after 0 -> also_ok
end.
Hope this clarify things a bit.
V.
----- Original Message -----
From: "datacompboy" <datacompboy@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Monday, October 02, 2006 5:27 AM
Subject: [erlang-questions] Bug ?!
>
> 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?!
> --
> --- suicide proc near\n call death\n suicide endp
> _________________________________________________________
> Post sent from http://www.trapexit.org
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list