Nothingness

Ulf Wiger etxuwig@REDACTED
Thu Oct 25 10:24:52 CEST 2001


On Wed, 24 Oct 2001, Erik Pearson wrote:

>Hi,
>
>I'm now hip-deep into my first Erlang project. It has been exciting, and
>very productive.
>
>I have encountered issues, of course. The application is very
>data-centric -- analyzing tab delimited and fixed-column-width tables,
>importing them into mnesia tables, and subsequently using these tables
>for lots of stuff.

You might want to look at the RDBMS contrib. It has, for one
thing, an import facility for a sort of tab-delimited text files.
It also has its own weird definition of a null value: '#.[].#'
It's sort of an Erlang tradition to invent an atom that no sane
user would want to input.

Atoms are stored very efficiently in RAM, but on disk, you should
expect them to expand to strings.


>It seems to me that the one solution would be a new disjoint
>datatype which represents the null value, and which has only
>one value "null".  The null value could be assigned by a
>primitive null(), values could be tested for nullness with
>null(Value), and could be stored efficiently.

I believe it is generally accepted that any proper null handling
must be done in the underlying runtime architecture -- not in the
application. Erlang should have a proper NULL representation, and
probably also infinity and negative infinity.

In some applications, I've stored data internally wrapped inside
a tuple, e.g. {X}. The null value could then safely be
represented as e.g. {} or null, as it cannot be confused with a
legal value. The interesting twist to this is that you can also
use the Erlang ordering rules to represent infinity and negative
infinity:

If {} ::= NULL, [] ::= infinity, '-infinity' ::= -(infinity),
then:

'-infinity' < {X} < [] for all X, and
{} <> {X} (of course, and also {} < {X}, but strictly speaking,
this is irrelevant, as NULL has no useful ordering.)

/Uffe
-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB




More information about the erlang-questions mailing list