[erlang-questions] Newbie question about line endings

Joe Armstrong erlang@REDACTED
Thu Dec 22 14:30:59 CET 2011

On Wed, Dec 21, 2011 at 8:21 PM, August Schwartzwald <
august.schwartzwald@REDACTED> wrote:

> Hi,
> I started to learn Erlang about a month ago. I really like it and think
> that with some more practice it will become a both unique and powerful tool
> in my growing box of programming languages. However, there is one thing
> about it that I find extremely annoying: The line endings.
> I currently know 5 programing languages, they have either 0 (python) or 1
> way to end lines (usually the ';' character). Erlang totally stands out
> here and requires that lines are ended in one of 4 different ways.
> Did some googling without finding any good reason to why the language
> works in this way. Can anyone here explain this?

There is no such ting as a "Line" in Erlang. Everything is a "form" so
there are no
line ending only form endings. A form is ended by a top-level "dot

Dot is a period "." white space is a blank,tab,newline or comment.
Comments start with "%" and are terminated by a newline

Top level means dot-whitespace is not contained inside a string, a quoted
atom or a comment.

The dot-whitespace convention came from Prolog, this is because Erlang was
first implemented in Prolog.

I don't really know why this convention was adopted in Prolog - but it might
have been done to simplify error handling. If you get a parse error in a
the parser wants to recover in some way. In Erlang/Prolog the strategy for
error recovery is extremely simple, if you get a parse error in a form the
parser just reports the error and goes to the next form - what constitutes
a form can be seen easily by only
looking at the stream of tokens generated by the tokeniser. This make
from parse errors very simple.

Dot-whitespace can be viewed as a synchronizing token for the purposes of
recovery during parsing of incorrect forms.

The easiest was to think of a form, is that it's like a sentence in English.

In your mail which posed this question, you ended  most sentences with
dot whitespace (the exception was ? as a terminator), so Erlang forms are
like English sentences.

Just like in English semicolons are "long range" operators and separate
whereas commas separate short range constructs.



> Thanks
> ______________________________**_________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111222/ddb8ed5a/attachment.htm>

More information about the erlang-questions mailing list