Erlang (programming language)#Tutorials#Terms

The metadata subpage is missing. You can start it via filling in this form or by following the instructions that come up after clicking on the [show] link to the right.

Do you see this on PREVIEW? then SAVE! before following a link.

* * *

To find out more about the use of metadata for the management of Citizendium pages, see CZ:Metadata.

You may see this box for one of two reasons. Either:

A \- New page has been created, or subpages template was added to an existing page

B \- Cluster move is in progress

Click either the A or B link for further instructions.

[Feel free to recommend improvements to the text or links in this template]

* * *

#### A - For a New Cluster use the following directions

Subpages format requires a metadata page.

Using the following instructions will complete the process of creating this article's subpages.

1. Click the blue "metadata template" link below to create the page.
2. On the edit page that appears paste in the article's title across from "`pagename =`".
3. You might also fill out the checklist part of the form. Ignore the rest.

For background, see Using the Subpages template Don't worry--you'll get the hang of it right away.
4. Remember to hit Save!

the "metadata template".

However, you can create articles without subpages. Just delete the {{subpages}} template from the top of this page and this prompt will disappear. :) Don't feel obligated to use subpages, it's more important that you write sentences, which you can always do without writing fancy code.

[Feel free to recommend improvements to the text or links in this template]

* * *

#### B - For a Cluster Move use the following directions

The metadata template should be moved to the new name as the first step. Please revert this move and start by using the Move Cluster link at the top left of the talk page.

The name prior to this move can be found at the following link.

* * *

[Feel free to recommend improvements to the text or links in this template]

* * *

* * *

The basic unit of expressing a value in Erlang is the term. Terms are comprised of one of Erlang's simple or complex types.

## Integers[edit]

Integer constants are written as numbers, optionally prefixed with a base and the octothorpe (`#`):

1> 2.

2> 16#ff.
255
3> 2#1011.

Erlang uses arbitrary-precision integers, which support integers with any number of digits.

Erlang also provides another syntactic shortcut: you can write an integer as the dollar sign (`$`) and a character, and the value is the ASCII value of that character. This is of use when handling strings, as strings are typically represented in Erlang as lists of integers (see Strings, below).

## Floats[edit]

Floats (floating-point numbers) are written as numbers with decimal places, optionally with an exponent separated from the number with the letter `e`.

4> 1.2.
1.20000
5> 1.0.
1.00000
6> 2.0e-4.
2.00000e-4

## Atoms[edit]

Atoms are named constants. Atoms begin with a lower-case letter and can contain letters, digits and the underscore character (`_`); or they are quoted with single quotes (`'`).

1> ok.

2> 'OKAY'.
'OKAY'
3> this_is_an_atom.
this_is_an_atom

The special atoms true and false represent boolean values.

Atoms are often used as the keys in key-value pairs, indicators of success and failure (e.g. ok and error) and to identify parts of a complicated structure for Pattern Matching.

## Tuples[edit]

Tuples are terms composed of multiple values, and are of fixed length. Tuples are surrounded by braces (`{` and `}`) and the elements of the tuple (any Erlang term, including tuples) separated by commas.

1> {ok, 9}.
{ok,9}
2> {true, {127, 0, 0, 1}}.
{true,{127,0,0,1}}
3> {box, {width, 10}, {height, 35}}.

The 3rd examples shows something called a tagged tuple. Where possible use tagged tuples as they make it clear what the tuple is suppose to represent. Later on we will look at records which is just a shorthand for tagged tuples.

## Lists[edit]

Lists are terms composed of multiple values, of varying length. Lists are surrounded by brackets (`[` and `]`) and each member of the list (any Erlang term, including lists) separated with commas.

Lists can also be composed of a head and tail portion, separated by the vertical bar character (`|`): `[Head|Tail]`. The Tail can be any valid Erlang term, but is usually a list representing the members of the list after the head.

1> [one, two, three].
[one,two,three]
2> [1, 2|[3, 4, 5]].
[1,2,3,4,5]
3> [{key1, value1}, {key2, value2}].
[{key1,value1},{key2,value2}]

Lists in which the smallest possible tail is the empty list (`[]`) are known as well-formed lists.

### Strings[edit]

Erlang has no separate string type. Strings are usually represented by lists of integers (and the string module of the standard library manipulates such lists). Each integer represents the ASCII (or other character set encoding) value of the character in the string. For convenience, a string of characters enclosed in double quotes (`"`) is equivalent to a list of the numerical values of those characters.

1> "one".
"one"
2> [$o, $n, $e].
"one"
3> $o.
111
4> $n.
110
5> $e.
101
6> [111, 110, 101].
"one"

The Erlang shell "guesses" whether a given list is a printable string and prints it that way for convenience. Also, there are a number of modules that enable unicode.

## Pids[edit]

A Pid or process id is a special type in Erlang. To see what one looks like you can get the pid of yourself() with self().

1> self().
<0.29.0>

## Refs[edit]

A ref (or reference) is a term which is unique, even across Erlang nodes. You can create a new ref by calling erlang:make_ref/0.

2> erlang:make_ref().
#Ref<0.0.0.41>

## Other types[edit]

Erlang has other types, such as funs (closures), bit-strings, binaries (continuous blocks of arbitrary data) and ports (port identifiers), that will be covered in their appropriate sections.