Introduction to Erlang : Basic Types (1/2)
- Introduction to Erlang post series
- Introduction to Erlang : Installing Erlang
- Introduction to Erlang : Typing
- Introduction to Erlang : Basic Types (1/2)
- Introduction to Erlang : Basic Types (2/2)
- Introduction to Erlang : Modules & Compilation
- Introduction to Erlang : Declaring Functions
- Introduction to Erlang : Control Flow
- Introduction to Erlang : Recursion (1/2)
- Introduciton to Erlang : Recursion (2/2)
- Introduction to Erlang : BIFs & Predefined Modules
- Introduction to Erlang : List & lists Module
- Introduction to Erlang : List Comprehension
- Introduction to Erlang : Concurrency (Processes)
- Introduction to Erlang : Message Passing
- Introduction to Erlang : Shared Memory Example
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. |
Pages: 1 2