Erlang Programming

Dark Agent

Expert Member
Joined
Nov 30, 2008
Messages
2,370
Reaction score
274
Morning,

I battling for 2 hours and over. I want to create a module with 2 functions and 2 function overloaded.

The following works for one function
Code:
-module(boolean).
-export([b_not/1]).

b_not(true) -> false;
b_not(false) -> true.

This not working
Code:
-module(boolean).
-export([b_and/1,b_and/2,b_not/1]).

b_not(true) -> false;
b_not(false) -> true;
b_and(true,true) -> true;
b_and(Other) -> false.

I get the following errors.
boolean.erl:6: head mismatch
boolean.erl:2: function b_and/1 undefined
boolean.erl:2: function b_and/2 undefined
boolean.erl:2: function b_not/1 undefined
Any clue how to approach it or fix it.
I tried tricks like export separate but more errors.
Thanks in advance
 
I figured it out,

; is use for overloading with the same arity(parameters)

Code:
-module(boolean).
-export([b_and/2,b_not/1,b_and/1]).

b_not(true) -> false;
b_not(false) -> true.
b_and(true,true) -> true.
b_and(Other) -> false .

Thanks:D
 
Top
Sign up to the MyBroadband newsletter
X