[erlang-questions] second try for understanding recursion
Erik Søe Sørensen
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
- '' 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
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...
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
Den 08/02/2015 11.56 skrev "Roelof Wobben" <r.wobben@REDACTED>:
> 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
> so far I have this :
> % 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) ->
> % is true is given, the answer will be false
> b_not(true) ->
> Is this a good try or can I change anything ?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions