Erlang is a general purpose functional programming language and a runtime environment. It has built in support for concurrency, fault tolerance, distribution and highly scalable used for applications require high uptime. Erlang is available as an open source. Erlang was originally developed to be used in several large telecommunication systems where require high concurrency , availability and fault tolerance.
OTP is a set of useful middleware, libraries, and tools written in the Erlang programming language. It includes its own distributed database, applications to interface towards other languages, debugging and release handling tools and it is important part of the open-source distribution of Erlang. The name OTP stand for Open Telecom Platform, which was a branding attempt before Ericsson released Erlang/OTP as opensource.
Data Types in Erlang-
- Bit Strings and Binaries
- Port Identifier
By calling erlang: disconnect_node (Node) will force disconnection of the node.
A Erlang module consists of a sequence of attributes and functions, each terminated by period (.)
A Erlang module has the same name as base file name. for example search_user.erl module name will be search_user.
A bit string is a erlang data type used to store an area of untyped memory. Bit strings are represented using the bit syntax. Bit strings that consist of a number of bits that are divisible by eight, are called binaries
A pattern matching is a way of checking a given sequence of terms with some other pattern of terms and find out if it matches or not. In pattern matching, a left-hand side pattern is matched against a right-hand side term. If the pattern match successfully, any unbound variables in the pattern become bound, If the pattern matching fails, a run-time error occurs.
PID stand for Process Identifier. It is a datatype used for holding the unique process identifiers which are assigned to process when created. Processes communicate by sending and receiving messages through PID. Messages are sent by the send operator ! and received by calling receive keyword.
The following are the way to include file in Erlang-
- include (File).
- include_lib (File).
Erlang is designed for massive concurrency that is achieved by creating processes in Erlang. Erlang processes are lightweight that can grow and shrink dynamically with small memory footprint, fast to create and terminate, and the scheduling overhead is low.
The process is created by calling spawn(built in function), and spawn forms a new process and returns the pid.
spawn(Module, Name, Args) -> pid()
Module = Name = atom()
Args = [Arg1,...,ArgN]
ArgI = term()
AÂ guard sequenceÂ is a sequence of guards, separated by semicolon (;). The guard sequence is true if at least one of the guards is true. (The remaining guards, if any, are not evaluated.)
Valid guard expressions are
- The atom true
- Other constants (terms and bound variables), all regarded as false
- Calls to the BIFs specified in table Type Test BIFs
- Term comparisons
- Arithmetic expressions
- Boolean expressions
- Short-circuit expressions (andalso/orelse)
The following are pre-defined Macros in Erlang-
- ? Module: Ireturns the name of the current module.
- ? Module_String: returns the name of the current module, as a string
- Â ? File: returns the current file name
- Â ? Line: returns the current line number
- ? Machine: returns the current machine name, â€˜BEAM.â€™
epmd is a small name server which is used by Erlang programs when establishing distributed Erlang communications. It is also point out as an Erlang Port Mapper Daemon. It used for mapping the symbolic node names to machine addresses.
A map is a compound data type with a variable number of key-value pair.Each key-value association in the map is called an association pair. The key and value parts of the pair are called elements. The number of association pairs is called the size of the map.
Hot swapping is a mechanism to replace existing code with new one without stopping the system.
A record is a data structure which is used for storing a fixed number of elements. It is similar to a struct in C, has named fields. Records are translated to tuple expressions during compilation.