Introduction to Erlang : Basic Types (1/2)

Command Terminator

Erlang uses a simple dot (.) as the command terminator. Consequently every correct Erlang statement should terminate with a dot.

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

The Most Basic Types

I will introduce the data types of Erlang and the basic operations on them by example. Most of the material presented today will look familiar to other programming languages. The next post will present some more sophisticated data types.

Integers

The most foundamental type is, as usual, the integer.

Operations
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.
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