# [erlang-questions] second try for understanding recursion

Erik Søe Sørensen eriksoe@REDACTED
Sun Feb 8 12:44:17 CET 2015

```OK, I have a few comments:
- why handle '' in your implementation of not ? I get the suspicion that
either you've been exposed to some other language where there was some
special value to always have to handle, or that you've been looking for
inspiration in some string-related recursion examples? (Bonus question: how
would your implementation of not in Haskell look like? Would it have three
clauses? )
- '' is not a string, but an atom. They are different beasts.
- so far, there's no recursion at all. Nor would you need recursion for
implementing not, or, and etc.
Why are you asking questions before you get to the recursion part, in a
post mentioning recursion in the title? (You are allowed to, of course, but
the rest of us are allowed to be confused by it :-))
As I understand the task, it is about writing a module which literally
takes (representations of) boolean expressions, such as "true AND (false OR
true)" and calculates the result. That does require recursion (as well as
choosing a suitable data structure for representing expressions).
Starting with the functions mentioned in the task description, as you have
dine,  sounds like a good idea, though.

- Finally: there are two parts to good code: 1) does it work and 2) is it
well written. (Well, also 1b) how little does it take to make it stop
working.)
For 2), this mailing list can be a good source of help. But 1) you can do
yourself - you could eg add a test  function to your module:
test () ->
false = b_not(true),
%... other test cases...
ok.

A side effect of this is signalling your level of understanding in mailing
list posts, improving the chance of answers at the right level.
(It may be clear at this point that I don't really know at which level to

Hoping this helps somehow
/Erik
Den 08/02/2015 11.56 skrev "Roelof Wobben" <r.wobben@REDACTED>:

> Hello,
>
> I have studied recursion the last few weeks by using Haskell and I think I
> understand it.
>
> I  did a portion of 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 far I have this :
>
> -module(boolean).
>
> -export([b_not/1]).
>
> % if a empty string is given , the answer will be a empty string.
> b_not('') ->
>   '';
>
> % is false is given, the answer will be true.
> b_not(false) ->
>   true;
>
> % is true is given, the answer will be false
> b_not(true) ->
>   false.
>
> Is this a good try or can I change anything ?
>
> Roelof
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150208/358aa12a/attachment.htm>
```