Introducing the Erlang Language Why Erlang?  Exemplifies the “you can have code and concurrency that is free from side effects…there is no other way”

Slides:



Advertisements
Similar presentations
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
Advertisements

CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Single assignment store Kernel language syntax Carlos Varela.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Introduction to Python
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
Haskell. 2 GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Computer Science 101 Introduction to Programming.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
CIT 590 Intro to Programming Lecture 5 – completing lists.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Practical Erlang Programming Basic Erlang. © Erlang Training and Consulting Ltd2Basic Erlang Practical Erlang Programming.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Copyright Curt Hill Variables What are they? Why do we need them?
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Working With Objects Tonga Institute of Higher Education.
RUBY by Ryan Chase.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Python Let’s get started!.
Welcome to AP Computer Science A We use the Java language, but this class is much more rigorous than Intro to Java More programming, but also more theory.
Error Example - 65/4; ! Toplevel input: ! 65/4; ! ^^ ! Type clash: expression of type ! int ! cannot have type ! real.
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
CPS120: Introduction to Computer Science Variables and Constants.
Python Programming Lecture II. Data Data is the raw material that programs manipulate. Data comes in different flavours. The basic ones are called “primitive.
1 Scheme (Section 11.2) CSCI 431 Programming Languages Fall 2003.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
String and Lists Dr. José M. Reyes Álamo.
Types CSCE 314 Spring 2016.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Python Let’s get started!.
More Functional Programming
Haskell.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2017.
Introduction to Python
Control Flow Chapter 6.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
String and Lists Dr. José M. Reyes Álamo.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
Type & Typeclass Syntax in function
Python Primer 1: Types and Operators
Haskell Types, Classes, and Functions, Currying, and Polymorphism
Department of Computer Science
(more) Python.
Declarative Computation Model Single assignment store (VRH 2
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
The Data Element.
Primitive Types and Expressions
The Data Element.
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introducing the Erlang Language Why Erlang?  Exemplifies the “you can have code and concurrency that is free from side effects…there is no other way” perspective  Real language used to build real systems  A pretty good, practical book exists to use as a text  Multi-core applications  Fault-tolerant applications

Erlang is a Functional Language Lots of definitions but some implications  Computation is primarily done by evaluating functions that take immutable values as inputs and produce immutable values as outputs  Programs are written by defining functions (in terms of other functions)  Functions are side-effect free Other functional languages: Haskell, Standard ML, LISP (in some variants) You can program functionally in imperative languages (e.g. C, Java, etc.) but some make it easier than others Automatic storage management (GC) is almost always a feature of functional languages (but not vice-versa)

Erlang values Numbers  Integers with arbitrary precision (dd*)  Floating point (d*d.dd*) Tuples  {value [, value]*} ; 1-tuple allowed and different from the contained value: 1 != {1}  Tuple models data structures of known fixed size Atoms  Alphanumeric sequences starting with lower-case letter (may contain but not start with _  Any sequence enclosed in single quotes  The value of an atom is itself Lists  Sequence of values of unknown size  Compare to python tuples and lists – Erlang lists are not mutable!

An Erlang idiom using tuples struct person { char *first; char *last }; -- C {person, {first, “carl”}, {last, “hauser”}} – this is just a value; note the use of atoms as tags in the tuples Erlang is a dynamically, strongly typed language. Using tags helps people keep things straight about programs. Compare {“carl”, “hauser”}

More about lists  List values can be written directly – [value, value, …, value] or created one element at a time using the list constructor [value, …, value | list]  The first element of a list is called the head  Everything else is the tail

Strings Erlang strings are really just lists of integers 5> "abc". "abc" 6> [1|"abc"]. [1,97,98,99] Shell has a special rule for printing lists that contain only printable characters The integer for a character can be written $c 7> $a. 97 This feels like a hack to me

Erlang variables Start with upper-case letter (enforced convention for human beings sake) Are write-once  A new variable is called unbound  After assignment a variable is said to be bound and cannot be further changed (limits the possibility for side effects!) “assignment” is technically the wrong term – more properly called binding

Erlang approach to binding: assertion of equality Idea: a form such as X = {1, 3} is an assertion of equality between X and {1, 3}. If something equals something else then they can’t later be not equal. Hence the bind-once rule. 9> X = {1,3}. {1,3} 10> x. x 11> X. {1,3} 12> X=X. {1,3} 13> X={1,3}. {1,3} 14> X={1,4}. ** exception error: no match of right hand side value {1,4}

Binding using pattern matching You may recall this idea from 355 if you talked about ML there What if the LHS is not a single variable but something that looks like a value but with variables embedded at some places 17> {Y,Z}=X. {1,3} 18> Y. 1 19> Z. 3 You may have also noticed this in Python >>> a = [1,2,3] >>> [d,e,f] = a >>> d 1 >>> e 2 >>> f 3

More pattern matching - lists 22> L1 = [0,1,2,3,4]. [0,1,2,3,4] 23> [H|T] = L1. [0,1,2,3,4] 24> H. 0 25> T. [1,2,3,4]

Assignment Before next class  Skim Chapters 2-5; read chapter 7  Install Erlang and work through (at the very least) the examples in Chapter 6 Don’t worry about the version: whatever precompiled version is available for your system should be fine