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
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)
Pages: 1 2