[erlang-questions] stuck at a exercise
Richard A. O'Keefe
Fri Jan 30 05:32:11 CET 2015
On 27/01/2015, at 3:35 am, Roelof Wobben <r.wobben@REDACTED> wrote:
> Second problem .
> I added a second clause to it like this:
> b_not(true) ->
=======^ This ends with a full stop. A full stop says “this is the absolute
and total end of this function definition. There is no more to say about this
function. I have done with it. It’s finished. There will never be any more
rules for this function in this file. End of story. Done!”
> b_not(false) ->
But whoops! You are trying to define b_not/1, but b_not/1 is already defined.
> but now I see this message ;
> boolean.erl:8: function b_not/1 already defined
> Which I do not understand because here the same approach is used :
No it is not.
BETWEEN clauses you must put SEMICOLONS (;).
AT THE END of a function you must put a FULL STOP (.).
Now this is an arbitrary fact about Erlang syntax. It did not have to be
that way. Here, for example, is a snippet of Prolog code, which is parsed
correctly when the ‘funnel’ preprocessor is loaded first.
| data bool ---> false | true.
| b_not(false) -> true.
| b_not(true) -> false.
So it is NOT stupid to put full stops after clauses.
It just happens to be wrong in Erlang.
In Erlang’s defence it can be said that it follows normal English
punctuation. Semicolons separate clauses of a sentence; full stops
Being a Prolog programmer of many years’ standing, I find this quirk of
Erlang’s a constant “faux ami”, and I wish the parser would just emit a
warning message and carry on.
More information about the erlang-questions