Reputation: 5575
I'm trying to follow a tutorial on Erlang lists and I'm having difficulty passing an argument to a list. The following is the code, I'm unsure how to run it, I get the error,
exception error: no function clause matching insert
I've tried
cases:insert(1,[0]).
on the command line and many others...
-module(cases).
-export([insert/2]).
insert(X,[]) ->
[X];
insert(X,Set) ->
case lists:member(X,Set) of
true -> Set;
false -> [X|Set]
end.
Upvotes: 0
Views: 1180
Reputation: 2612
The code you've posted works fine.
You may want to recompile it with c(cases)
then give it a shot.
But it works just fine for me, I've copied and pasted it into cases.erl and this is the result of the command line:
7> cases:insert(0,[1]).
[0,1]
Upvotes: 2