user2092864
user2092864

Reputation:

Erlang: No Match of right hand side value error

I'm trying to create a representation of some towers in erlang and when I try to run the following command, a no match of right hand side value appears.

T = towers:create(5).

Code:

create( N ) ->
    [{tower1, Tower1 = lists:seq(1,N)}, {tower2, Tower2 = []}, {tower3, Tower3 = []}].

Upvotes: 0

Views: 488

Answers (1)

zxq9
zxq9

Reputation: 13154

You are assigning variables that go unused, which will cause a compiler warning, but not actually fail. This works just fine:

-module(towers).
-export([create/1]).

create( N ) ->
    [{tower1, lists:seq(1,N)}, {tower2, []}, {tower3, []}].

In use:

1> c(towers).
{ok,towers}
2> towers:create(5).
[{tower1,[1,2,3,4,5]},{tower2,[]},{tower3,[]}]

Upvotes: 2

Related Questions