[erlang-questions] Directly matching record fields illegal?

Hynek Vychodil <>
Mon Dec 31 12:44:12 CET 2007


I don't understand what you want do.
If you want make new record likely Foo but with some atribute same as
Bar you must write (14):

 1> rd(foo, {ref=1, val=1}).
foo
12> Foo = #foo{ref=1,val=1}.
#foo{ref = 1,val = 1}
13> Bar = #foo{ref=2,val=2}.
#foo{ref = 2,val = 2}
14> Baz = Foo#foo{val=Bar#foo.val}.
#foo{ref = 1,val = 2}

If you want make matching constrain, you must write:

15> Bar = Bar#foo{ref = Foo#foo.ref}.
** exited: {{badmatch,{foo,1,2}},[{erl_eval,expr,3}]} **

or:

17> F = Foo#foo.ref, F = Bar#foo.ref.
** exited: {{badmatch,2},[{erl_eval,expr,3}]} **

But if you want just compare, write

18> Foo#foo.ref == Bar#foo.ref.
false

On 12/31/07, Vance Shipley <> wrote:
> This suprised me, has it always been this way?
>
>      5> Foo#foo.ref = Bar#bar.ref.
>      ** 1: illegal pattern **
>
>      6> F = Foo#foo.ref.
>      1
>      7> B = Bar#bar.ref.
>      1
>      8> F = B.
>      1
>
> --
>         -Vance
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>


-- 
--Hynek (Pichi) Vychodil



More information about the erlang-questions mailing list