From 9fe8adf35c16ab5d4566b03f3b36863c90b5b6dd Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 12 Mar 2015 15:35:13 +0100 Subject: Update Erlang Reference Manual Language cleaned up by the technical writers xsipewe and tmanevik from Combitech. Proofreading and corrections by Hans Bolinder. --- system/doc/reference_manual/data_types.xml | 164 ++++++++++++++++------------- 1 file changed, 93 insertions(+), 71 deletions(-) (limited to 'system/doc/reference_manual/data_types.xml') diff --git a/system/doc/reference_manual/data_types.xml b/system/doc/reference_manual/data_types.xml index 37c0db5ff7..6226fa2f31 100644 --- a/system/doc/reference_manual/data_types.xml +++ b/system/doc/reference_manual/data_types.xml @@ -4,7 +4,7 @@
- 20032013 + 20032015 Ericsson AB. All Rights Reserved. @@ -28,12 +28,12 @@ data_types.xml
+

Erlang provides a number of data types, which are listed in + this section.

Terms -

Erlang provides a number of data types which are listed in this - chapter. A piece of data of any data type is called a - term.

+

A piece of data of any data type is called a term.

@@ -44,16 +44,17 @@ $char

- ASCII value of the character char.
+ ASCII value or unicode code-point of the character + char. base#value

- Integer with the base base, which must be an + Integer with the base base, that must be an integer in the range 2..36.

In Erlang 5.2/OTP R9B and earlier versions, the allowed range is 2..16.
-

Examples:

+

Examples:

 1> 42.
 42
@@ -75,11 +76,11 @@
 
   
Atom -

An atom is a literal, a constant with name. An atom should be +

An atom is a literal, a constant with name. An atom is to be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @.

-

Examples:

+

Examples:

 hello
 phone_number
@@ -90,11 +91,11 @@ phone_number
   
Bit Strings and Binaries

A bit string is used to store an area of untyped memory.

-

Bit Strings are expressed using the +

Bit strings are expressed using the bit syntax.

-

Bit Strings which consists of a number of bits which is evenly - divisible by eight are called Binaries

-

Examples:

+

Bit strings that consist of a number of bits that are evenly + divisible by eight, are called binaries

+

Examples:

 1> <<10,20>>.
 <<10,20>>
@@ -102,12 +103,14 @@ phone_number
 <<"ABC">>
 1> <<1:1,0:1>>.
 <<2:2>>
-

More examples can be found in Programming Examples.

+

For more examples, + see + Programming Examples.

Reference -

A reference is a term which is unique in an Erlang runtime +

A reference is a term that is unique in an Erlang runtime system, created by calling make_ref/0.

@@ -116,34 +119,42 @@ phone_number

A fun is a functional object. Funs make it possible to create an anonymous function and pass the function itself -- not its name -- as argument to other functions.

-

Example:

+

Example:

 1> Fun1 = fun (X) -> X+1 end.
 #Fun<erl_eval.6.39074546>
 2> Fun1(2).
 3
-

Read more about funs in Fun Expressions. More examples can be found in Programming - Examples.

+

Read more about funs in + Fun Expressions. For more examples, see + + Programming Examples.

Port Identifier -

A port identifier identifies an Erlang port. open_port/2, - which is used to create ports, will return a value of this type.

+

A port identifier identifies an Erlang port.

+

open_port/2, which is used to create ports, returns + a value of this data type.

Read more about ports in Ports and Port Drivers.

Pid -

A process identifier, pid, identifies a process. - spawn/1,2,3,4, spawn_link/1,2,3,4 and - spawn_opt/4, which are used to create processes, return - values of this type. Example:

+

A process identifier, pid, identifies a process.

+

The following BIFs, which are used to create processes, return + values of this data type:

+ + spawn/1,2,3,4 + spawn_link/1,2,3,4 + spawn_opt/4 + +

Example:

 1> spawn(m, f, []).
 <0.51.0>
-

The BIF self() returns the pid of the calling process. - Example:

+

In the following example, the BIF self() returns + the pid of the calling process:

 -module(m).
 -export([loop/0]).
@@ -166,14 +177,14 @@ who_are_you
Tuple -

Compound data type with a fixed number of terms:

+

A tuple is a compound data type with a fixed number of terms:

 {Term1,...,TermN}

Each term Term in the tuple is called an element. The number of elements is said to be the size of the tuple.

There exists a number of BIFs to manipulate tuples.

-

Examples:

+

Examples:

 1> P = {adam,24,{july,29}}.
 {adam,24,{july,29}}
@@ -191,7 +202,8 @@ adam
 
   
Map -

Compound data type with a variable number of key-value associations:

+

A map is a compound data type with a variable number of + key-value associations:

 #{Key1=>Value1,...,KeyN=>ValueN}

Each key-value association in the map is called an @@ -199,7 +211,7 @@ adam called elements. The number of association pairs is said to be the size of the map.

There exists a number of BIFs to manipulate maps.

-

Examples:

+

Examples:

 1> M1 = #{name=>adam,age=>24,date=>{july,29}}.
 #{age => 24,date => {july,29},name => adam}
@@ -214,16 +226,18 @@ adam
 6> map_size(#{}).
 0

A collection of maps processing functions can be found in - the STDLIB module maps.

-

Read more about Maps.

+ maps manual page + in STDLIB.

+

Read more about maps in + Map Expressions.

-

Maps are considered experimental during OTP 17.

+

Maps are considered to be experimental during Erlang/OTP R17.

List -

Compound data type with a variable number of terms.

+

A list is a compound data type with a variable number of terms.

 [Term1,...,TermN]

Each term Term in the list is called an @@ -231,20 +245,21 @@ adam the length of the list.

Formally, a list is either the empty list [] or consists of a head (first element) and a tail - (remainder of the list) which is also a list. The latter can + (remainder of the list). + The tail is also a list. The latter can be expressed as [H|T]. The notation - [Term1,...,TermN] above is actually shorthand for + [Term1,...,TermN] above is equivalent with the list [Term1|[...|[TermN|[]]]].

-

Example:

-[] is a list, thus

+

Example:

+

[] is a list, thus

[c|[]] is a list, thus

[b|[c|[]]] is a list, thus

-[a|[b|[c|[]]]] is a list, or in short [a,b,c].

-

+[a|[b|[c|[]]]] is a list, or in short [a,b,c]

+

A list where the tail is a list is sometimes called a proper list. It is allowed to have a list where the tail is not a - list, for example [a|b]. However, this type of list is of + list, for example, [a|b]. However, this type of list is of little practical use.

-

Examples:

+

Examples:

 1> L1 = [a,2,{c,4}].
 [a,2,{c,4}]
@@ -261,18 +276,19 @@ a
 7> length([]).
 0

A collection of list processing functions can be found in - the STDLIB module lists.

+ the lists manual + page in STDLIB.

String

Strings are enclosed in double quotes ("), but is not a - data type in Erlang. Instead a string "hello" is - shorthand for the list [$h,$e,$l,$l,$o], that is + data type in Erlang. Instead, a string "hello" is + shorthand for the list [$h,$e,$l,$l,$o], that is, [104,101,108,108,111].

Two adjacent string literals are concatenated into one. This is - done at compile-time and does not incur any runtime overhead. - Example:

+ done in the compilation, thus, does not incur any runtime overhead.

+

Example:

 "string" "42"

is equivalent to

@@ -284,12 +300,13 @@ a Record

A record is a data structure for storing a fixed number of elements. It has named fields and is similar to a struct in C. - However, record is not a true data type. Instead record + However, a record is not a true data type. Instead, record expressions are translated to tuple expressions during compilation. Therefore, record expressions are not understood by - the shell unless special actions are taken. See shell(3) - for details.

-

Examples:

+ the shell unless special actions are taken. For details, see the + shell(3) manual + page in STDLIB).

+

Examples:

 -module(person).
 -export([new/2]).
@@ -303,14 +320,15 @@ new(Name, Age) ->
 {person,ernie,44}

Read more about records in Records. More examples can be - found in Programming Examples.

+ found in + Programming Examples.

Boolean

There is no Boolean data type in Erlang. Instead the atoms true and false are used to denote Boolean values.

-

Examples:

+

Examples:

 1> 2 =< 3.
 true
@@ -329,76 +347,80 @@ true
\b - backspace + Backspace \d - delete + Delete \e - escape + Escape \f - form feed + Form feed \n - newline + Newline \r - carriage return + Carriage return \s - space + Space \t - tab + Tab \v - vertical tab + Vertical tab \XYZ, \YZ, \Z - character with octal representation XYZ, YZ or Z + Character with octal + representation XYZ, YZ or Z \xXY - character with hexadecimal representation XY + Character with hexadecimal + representation XY \x{X...} - character with hexadecimal representation; X... is one or more hexadecimal characters + Character with hexadecimal + representation; X... is one or more hexadecimal characters \^a...\^z

\^A...\^Z
- control A to control Z + Control A to control Z
\' - single quote + Single quote \" - double quote + Double quote \\ - backslash + Backslash - Recognized Escape Sequences. + Recognized Escape Sequences
Type Conversions -

There are a number of BIFs for type conversions. Examples:

+

There are a number of BIFs for type conversions.

+

Examples:

 1> atom_to_list(hello).
 "hello"
-- 
cgit v1.2.3