CS 3060: Programming Languages

Erlang

Robert C. Green II, Ph.D.

Day 1

Agent Smith

Key Points

  • Scalability
  • Concurrency
  • Reliability

Key Points

  • Your programs are going to be built entirely out of functions, with no objects anywhere.
  • Those functions will usually return the same values, given the same inputs.
  • Those functions will not usually have side effects, meaning they will not modify program state.
  • You will only be able to assign any variable once.

The Interpreter

                        
    erl
                        
                    

Atoms

A symbol is called an atom and begins with lowercase
                        
    red.
    Pill = blue.
    Pill.
                        
                    

Lists

                        
    [1, 2, 3].
    [1, 2, "three"].
    List = [1, 2, 3].
                        
                    

Tuples

                        
{one, two, three}.
Origin = {0, 0}.

{name, "Spaceman Spiff"}.
{comic_strip, 
    {name, "Calvin and Hobbes"}, 
    {character, "Spaceman Spiff"}}.
                        
                    

Pattern Matching

                        
 Person = {person, {name, "Agent Smith"}, 
                   {profession, "Killing programs"}}
          
          {person, {name, Name}, 
                   {profession, Profession}} = Person.
                        
                    

Pattern Matching

                        
    [Head | Tail] = [1, 2, 3].
                        
                    

Pattern Matching

                        
    [One, Two|Rest] = [1, 2, 3].
                        
                    

Functions

                        
-module(basic).
-export([mirror/1]).

mirror(Anything) -> Anything.
                        
                    

Functions

                        
-module(matching_function).
-export([number/1]).

number(one) -> 1;
number(two) -> 2;
number(three) -> 3.
                        
                    

Functions

                        
module(yet_again).
-export([another_factorial/1]).
-export([another_fib/1]).

another_factorial(0) -> 1;
another_factorial(N) -> N * another_factorial(N-1).

another_fib(0) -> 1;
another_fib(1) -> 1;
another_fib(N) -> another_fib(N-1) + another_fib(N-2)
                        
                    

Assignment

Start the Assignment

Read Day 2

Resources