[erlang-questions] stuck at a exercise

Leonard Boyce leonard.boyce@REDACTED
Mon Jan 26 15:24:32 CET 2015


Hi Roelof,

Welcome to Erlang.

On Mon, Jan 26, 2015 at 9:09 AM, Roelof Wobben <r.wobben@REDACTED> wrote:
> Hello,
>
> At a book im following with self-study I have to do this exercise :
>
> Write a module boolean.erlthat takes logical expressions and Boolean values
> (represented as the atoms  trueand  false) and returns their Boolean result.
> The functions
> you write should include b_not/1, b_and/2, b_or/2, and b_nand/2. You should
> not use
> the logical constructs  and,  or, and  not, but instead use pattern matching
> to achieve your
> goal.
>
> So I tried the first clause and came with this :
>
> -module(boolean).
>
> -export([boolean/1]).
>
> b_not({true}) ->
>   false.
>
> But as soon as I compile it I see these error messages :
>
> boolean.erl:3: function boolean/1 undefined
> boolean.erl:5: Warning: function b_not/1 is unused
>
> How to solve these ?

I'm sure to get some hate for this, but I often find it easiest to
explain in imperative programming terms to people new to the language;

module == class
public methods go in -exports([])
private methods are not exported and are only callable from within the
module itself

In your case you'd want to export the function b_not/1

Which would be callable as boolean:b_not(X)

You do not export the module name, only functions you want to be callable.

Leonard

> Roelof
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list