Erlang (programming Language) - Data Structures

Data Structures

Erlang has eight primitive data types:

  1. Integers: integers are written as sequences of decimal digits, for example, 12, 12375 and -23427 are integers. Integer arithmetic is exact and only limited by available memory on the machine. (This is called arbitrary-precision arithmetic.)
  2. Atoms: atoms are used within a program to denote distinguished values. They are written as strings of consecutive alphanumeric characters, the first character being a small letter. Atoms can contain any character if they are enclosed within single quotes and an escape convention exists which allows any character to be used within an atom.
  3. Floats: floating point numbers use the IEEE 754 64-bit representation. (Range: ±10308.)
  4. References: references are globally unique symbols whose only property is that they can be compared for equality. They are created by evaluating the Erlang primitive make_ref.
  5. Binaries: a binary is a sequence of bytes. Binaries provide a space-efficient way of storing binary data. Erlang primitives exist for composing and decomposing binaries and for efficient input/output of binaries.
  6. Pids: Pid is short for process identifier—a Pid is created by the Erlang primitive spawn(...) Pids are references to Erlang processes.
  7. Ports: ports are used to communicate with the external world. Ports are created with the built-in function (BIF) open_port. Messages can be sent to and received from ports, but these messages must obey the so-called "port protocol."
  8. Funs : Funs are function closures. Funs are created by expressions of the form: fun(...) -> ... end.

And two compound data types:

  1. Tuples : tuples are containers for a fixed number of Erlang data types. The syntax {D1,D2,...,Dn} denotes a tuple whose arguments are D1, D2, ... Dn. The arguments can be primitive data types or compound data types. The elements of a tuple can be accessed in constant time.
  2. Lists : lists are containers for a variable number of Erlang data types. The syntax denotes a list whose first element is Dh, and whose remaining elements are the list Dt. The syntax denotes an empty list. The syntax is short for ]]]. The first element of a list can be accessed in constant time. The first element of a list is called the head of the list. The remainder of a list when its head has been removed is called the tail of the list.

Two forms of syntactic sugar are provided:

  1. Strings : strings are written as doubly quoted lists of characters, this is syntactic sugar for a list of the integer ASCII codes for the characters in the string, thus for example, the string "cat" is shorthand for . It has partial support for unicode strings
  2. Records : records provide a convenient way for associating a tag with each of the elements in a tuple. This allows us to refer to an element of a tuple by name and not by position. A pre-compiler takes the record definition and replaces it with the appropriate tuple reference.

Erlang has no method of defining classes, although there are external libraries available.

Read more about this topic:  Erlang (programming Language)

Famous quotes containing the words data and/or structures:

    Mental health data from the 1950’s on middle-aged women showed them to be a particularly distressed group, vulnerable to depression and feelings of uselessness. This isn’t surprising. If society tells you that your main role is to be attractive to men and you are getting crow’s feet, and to be a mother to children and yours are leaving home, no wonder you are distressed.
    Grace Baruch (20th century)

    If there are people who feel that God wants them to change the structures of society, that is something between them and their God. We must serve him in whatever way we are called. I am called to help the individual; to love each poor person. Not to deal with institutions. I am in no position to judge.
    Mother Teresa (b. 1910)