From 9fe8adf35c16ab5d4566b03f3b36863c90b5b6dd Mon Sep 17 00:00:00 2001
From: Hans Bolinder Erlang provides a number of data types, which are listed in
+ this section. 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. Examples: Examples: 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: 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 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: More examples can be found in Programming Examples. For more examples,
+ see 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 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: Read more about funs in Read more about funs in A port identifier identifies an Erlang port. A port identifier identifies an Erlang port. Read more about ports in A process identifier, pid, identifies a process.
- A process identifier, pid, identifies a process. The following BIFs, which are used to create processes, return
+ values of this data type: Example: The BIF In the following example, the BIF Compound data type with a fixed number of terms: A tuple is a compound data type with a fixed number of terms: Each term There exists a number of BIFs to manipulate tuples. Examples: Examples: 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: 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: A collection of maps processing functions can be found in
- the STDLIB module Read more about
-
- ASCII value of the character
- Integer with the base
In Erlang 5.2/OTP R9B and earlier versions, the allowed range
is 2..16.
1> 42.
42
@@ -75,11 +76,11 @@
hello
phone_number
@@ -90,11 +91,11 @@ phone_number
1> <<10,20>>.
<<10,20>>
@@ -102,12 +103,14 @@ phone_number
<<"ABC">>
1> <<1:1,0:1>>.
<<2:2>>
-
1> Fun1 = fun (X) -> X+1 end.
#Fun<erl_eval.6.39074546>
2> Fun1(2).
3
-
+
+
1> spawn(m, f, []).
<0.51.0>
-
-module(m).
-export([loop/0]).
@@ -166,14 +177,14 @@ who_are_you
{Term1,...,TermN}
1> P = {adam,24,{july,29}}.
{adam,24,{july,29}}
@@ -191,7 +202,8 @@ adam
#{Key1=>Value1,...,KeyN=>ValueN}
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
Read more about maps in
Maps are considered experimental during OTP 17.
+Maps are considered to be experimental during Erlang/OTP R17.
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
Formally, a list is either the empty list
Example:
-
+
Example:
+
-
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
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
Strings are enclosed in double quotes ("), but is not a
- data type in Erlang. Instead a string
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 @@ aA 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
Examples:
+ the shell unless special actions are taken. For details, see the +Examples:
-module(person). -export([new/2]). @@ -303,14 +320,15 @@ new(Name, Age) -> {person,ernie,44}
Read more about records in
There is no Boolean data type in Erlang. Instead the atoms
Examples:
+Examples:
1> 2 =< 3. true @@ -329,76 +347,80 @@ true
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