[erlang-questions] atoms with newlines

Richard A. O'Keefe <>
Wed Feb 26 21:30:22 CET 2014

On 26/02/2014, at 10:56 PM, Valentin Micic wrote:

> If this is *really* necessary, wouldn't it be less confusing (or even more consistent) to consider:
> 1>  'foo'  \
> 1>  'bar'.
> foobar
> whereas: 
> 3> 'foo
> 3>bar'
> 'foo\nbar'
> includes a new line -- as already does.

No, and on two grounds.

First, backslash escapes are not a special notation
confined to Erlang.  They are supported in a wide
variety of languages.  Not just the "usual suspects"
in the C family.  There's Python, for example.  And
logic programming languages and functional languages too:

>>> print "a\
... b";
ab					-- Python

> "a\
- b";;
val it : string = "ab"			-- F# and O'CAML

?- X = 'a\
|    b'.
X = ab.					-- Prolog and Mercury

So having backslash+newline *silently accepted* and
do *exactly the opposite of what people expect* cannot
be a good thing.

We already have two ways to get a newline into an Erlang
string or atom:  a bare newline or a \n escape.  We really
do NOT need a third, especially one that is basically an
implementation accident.

It would be excusable to make backslash+newline an
always-reported syntax error.  People would get a nasty
surprise, but at least they wouldn't silently get the
wrong value in their program.  In fact I think that
*every* \<char> combination that is not explicitly
documented should be reported as a syntax error.

Second, it is currently the case that backslash has a
special meaning in Erlang *ONLY* inside quoted literals
(counting $\t as a quoted literal).  Your "less confusing
(or even more consistent)" proposal introduces a new
thing that *looks* like an operator but *isn't* one.
It is difficult to see how that is less confusing than
following common practice or more consistent with anything.

More information about the erlang-questions mailing list