Picture of Andrey Sergienko
Strange behavior
by Andrey Sergienko - Friday, 23 November 2012, 01:04 PM
 
Hello to all

I just finished 'Simple Pattern Matching' assignment (you can found it here: http://elearning.erlang-solutions.com/mod/assignment/view.php?id=92)

And I'm confused because it says:

Ooops. Test "boolean_tests:b_not_type_test_/0_16" failed. Hide info
Check whether the 'b_not' function refuses values other than atoms.

My b_not function is here:

b_not(A) when is_atom(A) ->
 true =/= A.

So it should refuse values other than atoms. But is fails on 'b_not_type' test.

Could someone explain, please, what's wrong with my function?

Thanks!

Picture of Roberto Aloi
Re: Strange behavior
by Roberto Aloi - Tuesday, 27 November 2012, 11:11 AM
 
Hi Andrey,

I guess the message is a bit misleading, here. What he's trying to say is that values different than booleans are accepted by your function:

b_not(foobar) -> true.

In fact, in Erlang, booleans are not a datatype. They're simply atoms. The message should say: "it should refuse values other than the atoms true and false".

Take that as a warning and not an error, though. It's merely something you should be aware of.