Posts Tagged ‘module’
Introduction to Erlang : BIFs & Predefined Modules
Built-in Functions (BIFs)
Erlang’s Built-in Functions (shorthand BIFs) are commonly used functions that are intergrated into the Erlang’s VM for performance reasons. Most of them belong to the erlang
module, but there are some in other modules, such as lists
.
The BIFs can be separated to standard and non-standard. The standard ones are auto-imported; they can be called without the use of the module name prefix (remember the effect of the -import(...)
directive). On the other hand, the non-standard ones have to be called following the normal module:function(...)
convension. In the erlang
module’s man pages (here) the distinction between standard and non-standard is visible by the lack or existence of the erlang
(module’s name) prefix.
elrang
abs/1
Arithmetic absolut value of an integer or float.
erlang:append_element/2
Appends an element to a tuple.
apply/2|3
Calls the function passed as a parameter.
atom_to_list/1
Returns a string which corresponds to the text representation of Atom.
Read the rest of this entry »
Introduction to Erlang : Modules & Compilation
Modules
A module is a container for functions; it provided the contained functions with a common namespace. Modules are used to organize functions in Erlang. Usually, a program in Erlang spans over more than one modules. You can imagine a module as a package in Java, or a header file in C.
Calling a Function
The calling convention in Erlang is module:function(argument1, argument2, ...)
. For example:
1> lists:max([1,3,2]). 3 |
Defining Modules
Lets say we want to create a module that will contain our own implementation of list functions and name it mlists
.
Read the rest of this entry »