[erlang-questions] Comparing (pattern-matching) records
Avinash Dhumane
avinash@REDACTED
Sat Mar 31 09:37:01 CEST 2012
I might have overlooked all the 3 books (for sections on records), but
couldn't find an explanation why a pattern matching error doesn't occur in
the last (7th) shell expression below.
Please.
Thanks.
$ cat rec.hrl
-record(rec, {a, b}).
$ erl
Erlang R14B02 (erts-5.8.3) [smp:2:2] [rq:2] [async-threads:0]
Eshell V5.8.3 (abort with ^G)
1> rr("rec.hrl").
[rec]
2> A=#rec{}.
#rec{a = undefined,b = undefined}
3> B=#rec{a=1}.
#rec{a = 1,b = undefined}
4> A=B.
** exception error: no match of right hand side value #rec{a = 1,b =
undefined}
5> {} = {1}.
** exception error: no match of right hand side value {1}
6> {rec, undefined, undefined} = {rec, 1, undefined}.
** exception error: no match of right hand side value #rec{a = 1,b =
undefined}
7> #rec{} = #rec{a=1}.
#rec{a = 1,b = undefined}
More information about the erlang-questions
mailing list