
wikipedia said:
Erlang is a general-purpose concurrent programming language and runtime system. The sequential subset of Erlang is a functional language, with strict evaluation, single assignment, and dynamic typing. For concurrency it follows the Actor model. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. The first version was developed by Joe Armstrong in 1986.[1] It supports hot swapping, thus code can be changed without stopping a system.[2] Erlang was originally a proprietary language within Ericsson, but was released as open source in 1998.
While threads are considered a complicated and error-prone topic in most languages, Erlang provides language-level features for creating and managing processes with the aim of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing instead of shared variables, which removes the need for locks.
While threads are considered a complicated and error-prone topic in most languages, Erlang provides language-level features for creating and managing processes with the aim of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing instead of shared variables, which removes the need for locks.
Getting Started:
To get started, download the Erlang SDK, which comes with a shell, which is used for compiling Erlang files as well as running some basic commands, like adding numbers and invoking functions. Erlang files (.erl extension) are used to store functions, and are referred to as modules. In order for the functions to be accessed outside of the module they are declaried in, they must be exported, as well as the module declared the head of the file. Modules are declared as such: -module(name)., and functoins are exported with the following syntax: -export([funcName/numArgs]).. Note how the . symbol is the terminator for each line. Individual commands within functions are separated by a semi-colon, and the function is ended with a period.
Example (primality checker):
-module(prime). -export([is_prime/1]). %the entry function, starts at N mod 2 is_prime(N) -> check_prime(N,2). %case 1: base case- nothing after is prime check_prime(N,K) when K >= N/2 -> N rem K /= 0; %case 2: If we can't disprove primality, go to the next number check_prime(N,K) when N rem K > 0 -> check_prime(N,K+1); %case 3: If we can disprove primality, stop. check_prime(N,K) when N rem K == 0 -> false.
In the Shell, to compile and run:
%compile
c:("path:/name.erl").
%if the compilation is successful
%a {ok, module_name} should appear
%if this is the case, you can invoke functions
%invoke a function- module:function(params).
prime:is_prime(100).
Resources:
Erlang Tutorial From Ericson
Ideas:
The Dining Philosophers Problem
Mergesort or Quicksort
Calculuate N!
Find the Nth Fibonacci Number

New Topic/Question
Reply





MultiQuote








|