Concatenating atoms

Thomas Johnsson XA (LN/EAB) thomas.xa.johnsson@REDACTED
Thu Feb 3 17:28:11 CET 2005

.. And this might be a good time to suggest an alternative in applications like these:
use integers/bignums instead of atoms. Like:

string_to_integer([]) -> 0;
string_to_integer([C|S]) -> C bor (string_to_integer(S) bsl 8).

integer_to_string(0) -> [];
integer_to_string(I) -> [I band 16#ff | integer_to_string(I bsr 8)].

30> A = stringinteger:string_to_integer("hej hopp i lingonskogen!"). 
31> stringinteger:integer_to_string(A).                             
"hej hopp i lingonskogen!"

Hopefully bignums are "represented sensibly" ie in one chunk, or at least 
more compactly than strings ... are they?

-- Thomas

-----Original Message-----
From: owner-erlang-questions@REDACTED
Sent: den 3 februari 2005 16:57
To: erlang-questions@REDACTED
Subject: RE: Concatenating atoms

Joe wrote:

> *Every* parser which accepts inputs from a communication 
> channel suffers from this
> problem is the set of atoms that it can create is unbounded.

>   This gives us a number of design choices.
> 	1) Accept that I have incorrect implementation that 
> will one day crash
> 	2) Prove that the atom table cannot overflow because 
> the alphabet is
> 	   finite and will not overflow the atom table
> 	3) Uses strings instead of atoms

This might be a good time to point out that xmerl
converts element and attribute names to atoms.

I've seen complaints on the list that xmerl is slow.
All other things being equal, switching over to using
strings instead would slow it down considerably
(not that I've measured this).


More information about the erlang-questions mailing list