Introduction to Erlang : Basic Types (1/2)

Characters

The characters in Erlang are represented as integers (the ASCII value):

1> 1
1> 2.
* 2: syntax error before: 2
1> 1.
1
2> 2.
2

Floats

Again, nothing special:

1> I = 17. % binding
17
2> I = 17. % pattern matching without binding
17
3> I = 18. % unsuccessful
** exception error: no match of right hand side value 18
4> I + 2. % addition
19
5> I - 4. % substraction
13
6> I * 4. % multiplication
68
7> I div 4. % integer division
4
8> I / 4. % division
4.25
9> I rem 4. % integer remainder
1
10> I == 4. % equality
false
11> I =/= 4. % unequality
true
12> I > 4.  % greater than
true
13> I >= 4. % greater-equal
true
14> I < 4. % lower than
false
15> I =< 4. % lower-equal
false
16> is_integer(I). % is integer ?
true
17> not(is_integer(I)). % is not integer ?
false
18> is_integer(3.3).
false
19> 2#10000. % integer in the form base#value
16
20> 4#100.  
16
21> 8#20. 
16
22> 10#16.
16
23> 16#1.

Atoms

Another Prolog’s influence is the atom data type. Atoms are literals, constants with names. Their meaning is usually defined by the programmer. For example, Erlang itself uses the atoms true and false with the semantcis that every programmer is used to. Note that there is not a Boolean type; true and false are simple atoms. Every character sequencre generated by the [a-z]([a-z0-9_@])* regular expression, or enclosed in single quotes () is an atom.

1> atom.
atom
2> atom@123.
atom@123
3> a_tom@123.
a_tom@123
4> wr ong.   
* 1: syntax error before: ong
4> 'this is not wr ong'.
'this is not wr ong'
5> '!!~~>>'.
'!!~~>>'

Next

In the next post I will present some more “elaborate” Erlang data types. (tuples, lists, strings, functions)

Series NavigationIntroduction to Erlang : TypingIntroduction to Erlang : Basic Types (2/2)

Pages: 1 2

Leave a Reply

*

Posts’ Calendar
March 2011
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031