Erlang (programming language)/Tutorials: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
imported>Eric Evers
Line 34: Line 34:


*[[Erlang_programming_language/Tutorials/Hello|Hello World (Serial)]]
*[[Erlang_programming_language/Tutorials/Hello|Hello World (Serial)]]
====Code Example====
-module(hello).
-export([start/0]).
start() ->
    io:format("Hello, world!\n").
====Analysis of the example====
The [[Hello World]] program (see above) appears in many programming languages books and articles as a cursory introduction into a language's [[syntax]]. The first hello world program was introduced in the book ''The C Programming Language''<ref name="K&R"/>.
<code>-module(hello)</code> tells the [[compiler]] to create a new module(library) called hello. The code tells us the file name for this code: hello.erl.
<code>-export([start/0]). </code> exports a function named start with 0 arguments to the world outside of this module called hello.
<code> start() -> </code> tells the compiler that there is a [[function]] named start() with no arguments.
<code>io:format("Hello, world!\n").</code> will make the program output <code>Hello, world!</code> and a new line (<code>\n</code>) on the screen.


===Hello World (parallel)===
===Hello World (parallel)===

Revision as of 19:24, 19 April 2008

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Tutorials [?]
 
Tutorials relating to the topic of Erlang (programming language).

Erlang Language Programming Tutorials

Overview

Syntax of functions

Functions are defined by the domain of the arguments and the number of arguemnts. A function ends with a period. A function defined over differnt domains are separated by semicolons. A fact function gives an answer that is sensitive to the domain of the input. With strings it gives a fact. With counting numbers it gives the factorial function.

fact("aloha") -> "Aloha is a greating";
fact(String) when is_a_list(String) -> 
    "no fact is known about " ++ String;
fact(0) -> 1;
fact(N) when is_integer(N) and (N > 0) -> 
    fact(N-1)*N;
fact(N) when N < 0 -> error.


Macros

-define(LIKERT_SCALE, lists:seq(1, 5)).

A = LIKERT_SCALE.

Simple Types

Advanced Types

Popular Modules

Example programs

Hello World (serial)

Hello World (parallel)

Parallel Hello

Prime Sieve (parallel with linda type coordination)

Prime Sieve with Linda

Autonomous Agents

Autonomous Agents in Erlang

See definition of Autonomous Agent.

Advanced OTP

ETS

ETS programming

Mimsia

References

1 - Erlang Man Pages at Erlang,org