[erlang-questions] atoms with newlines

Richard A. O'Keefe ok@REDACTED
Tue Feb 18 21:30:18 CET 2014


On 19/02/2014, at 3:04 AM, Vlad Dumitrescu wrote:
> Multi-line strings are a pain but at least I can understand the reason for having them. I can't find any reasonable use of atoms with names including newlines and I wonder if we could do anything about them... 

Since list_to_atom/1 can create atoms containing newlines,
then we had _better_ be able to print them somehow.

There is no token pasting for quoted atoms.  In Prolog,
where _any_ atom can be declared as an operator, such a
restriction is necessary.  In Erlang, where the set of
operators is fixed and quoted operators are not operators,
there's no obvious reason why 'foo' 'bar' could not be
read as a single atom.


There's one thing about Erlang atom reading that may be
an oversight, and is dangerously close to a bug:

m% ./erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> 'foo\n\
1> bar'.
'foo\n\nbar'

I had expected that <backslash><newline> would
- be rejected as a syntax error, or
- be discarded like in C and Prolog.

I did _not_ expect it to turn into <newline>.

The current on-line documentation
http://www.erlang.org/doc/reference_manual/data_types.html#id65925
has a table in section 2.14 showing the escape sequences.
(It would be nice to have a forward reference in section 2.3.)
That table is completely silent about \<newline>.

Section 2.14 also fails to mention that the escape
sequence are also accepted in character literals.
Anyone reading section 2.2 would surmise that they
were forbidden.  I suggest

	there are two Erlang-specific notations:
	* $char
	  The numeric code for the character char.
	  Any of the escape sequences in section 2.14
	  may be used.
	* base#value
	  ,,,






More information about the erlang-questions mailing list