C. Varela1 Programming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms Carlos Varela Rennselaer Polytechnic Institute September.

Slides:



Advertisements
Similar presentations
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Advertisements

Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Foundations of Programming Languages: Introduction to Lambda Calculus
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Single assignment store Kernel language syntax Carlos Varela.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
C. Varela1 Programming Languages (CSCI 4430/6969) History, Syntax, Semantics, Essentials, Paradigms Carlos Varela Rennselaer Polytechnic Institute August.
Programming Languages Structure
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
C. Varela1 Programming Languages (CSCI 4430/6969) Lambda Calculus Carlos Varela Rennselaer Polytechnic Institute September 17, 2007.
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
CS 415: Programming Languages Chapter 1 Aaron Bloomfield Fall 2005.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
 The design of the imperative languages is based directly on the von Neumann architecture  Efficiency is the primary concern  Low-level specifications:
Introduction to Programming Languages Where do we start to understand programming languages as a core concept of Computer Science? There are literally.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
1 Programming Language History and Evolution In Text: Chapter 2.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Programming Languages – An introduction. There are 10 types of people in the world −Those who understand binary −Those who don’t.
1 ML fun x -> e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors let f x = e variables These.
C. Varela1 Programming Languages (CSCI 4430/6430) Part 1: Functional Programming: Summary Carlos Varela Rennselaer Polytechnic Institute September 29,
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Fortran Fortran – Formula Translation –Developed by John Backus (IBM) in the mid 1950s. –It was a team effort and the design goal was to produce a translation.
Overview.  Explores the theoretical foundations of computing  What can and cannot be done by an algorithm  Most of the material predates computers!
C. Varela; Adapted w. permission from S. Haridi and P. Van Roy1 Functional Programming: Lists, Pattern Matching, Recursive Programming (CTM Sections ,
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Logical and Functional Programming
1-1 An Introduction to Functional Programming Sept
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 190 Programming Language Paradigms Fall 2014
Programming Language Paradigms ITSK2314 Lecture 3.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
History. Development Driven by Function Functions of a Programming Language –To describe computation for use by computers –To describe computation and.
Programming Language History and Evolution
Chapter 1. Introduction.
Programming Languages 2nd edition Tucker and Noonan
Chapter 2: Lambda Calculus
Functional Programming: Lists, Pattern Matching, Recursive Programming (CTM Sections , 3.2, , 4.7.2) Carlos Varela RPI September 12,
Why study programming languages?
PROGRAMMING LANGUAGES
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
Programming Language Design Concepts
Carlos Varela Rennselaer Polytechnic Institute September 1, 2017
Higher-Order Programming: Iterative computation (CTM Section 3
Programming Language History and Evolution
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Programming Languages 2nd edition Tucker and Noonan
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
Von Neumann Architecture
Overview of Programming Paradigms
Introduction to Programming Concepts (VRH )
Declarative Computation Model Single assignment store (VRH 2
CSE S. Tanimoto Lambda Calculus
Carlos Varela Rennselaer Polytechnic Institute September 8, 2015
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Carlos Varela Rennselaer Polytechnic Institute September 10, 2019
Presentation transcript:

C. Varela1 Programming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms Carlos Varela Rennselaer Polytechnic Institute September 1, 2015

C. Varela2 The first programmer ever Ada Augusta, the Countess of Lovelace, the daughter of the poet Lord Byron Circa 1843 Using Babbage’s Analytical Engine

C. Varela3 The first “high-level” (compiled) programming language FORTRAN 1954 Backus at IBM It was called “an automatic coding system”, not a “programming language” Used for numerical computing

C. Varela4 The first functional programming language Lisp 1958 McCarthy at Stanford For LISts Processing---lists represent both code and data Used for symbolic manipulation

C. Varela5 The first object oriented programming language Simula 1962 Dahl and Nygaard at University of Oslo, Norway Used for computer simulations

C. Varela6 The first logic programming language Prolog 1972 Roussel and Colmerauer at Marseilles University, France For “PROgrammation en LOGique”. Used for natural language processing and automated theorem proving

C. Varela7 The first concurrent programming language Concurrent Pascal 1974 Hansen at Caltech Used for operating systems development

C. Varela8 The first concurrent actor programming language PLASMA 1975 Hewitt at MIT Used for artificial intelligence (planning)

C. Varela9 The first scripting language REXX 1982 Cowlishaw at IBM Only one data type: character strings Used for “macro” programming and prototyping

C. Varela10 The first multi-paradigm programming language Oz 1995 Smolka at Saarland University, Germany A logic, functional, imperative, object-oriented, constraint, concurrent, and distributed programming language Used for teaching programming and prototyping

C. Varela11 Other programming languages Algol (Naur 1958) Cobol (Hopper 1959) BASIC (Kennedy and Kurtz 1964) Pascal (Wirth 1970) C (Kernighan and Ritchie 1971) Ada (Whitaker 1979) Smalltalk (Kay 1980) C++ (Stroustrop 1980) Eiffel (Meyer 1985) Java (Gosling 1994) C# (Hejlsberg 2000) Act (Lieberman 1981) ABCL (Yonezawa 1988) Actalk (Briot 1989) Erlang (Armstrong 1990) E (Miller et al 1998) SALSA (Varela and Agha 1999) ML (Milner 1973) Scheme (Sussman and Steele 1975) Haskell (Hughes et al 1987) Python (van Rossum 1985) Perl (Wall 1987) Tcl (Ousterhout 1988) Lua (Ierusalimschy et al 1994) JavaScript (Eich 1995) PHP (Lerdorf 1995) Ruby (Matsumoto 1995) Imperative Object-Oriented Actor-Oriented Functional Scripting

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy12 Declarative Computation Model Defining practical programming languages (CTM 2.1) Carlos Varela RPI September 1, 2015 Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy13 Programming Concepts A computation model: describes a language and how the sentences (expressions, statements) of the language are executed by an abstract machine A set of programming techniques: to express solutions to the problems you want to solve A set of reasoning techniques: to reason about programs to increase the confidence that they behave correctly and to calculate their efficiency

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy14 Declarative Programming Model Guarantees that the computations are evaluating functions on (partial) data structures The core of functional programming (LISP, Scheme, ML, Haskell) The core of logic programming (Prolog, Mercury) Stateless programming vs. stateful (imperative) programming We will see how declarative programming underlies concurrent and object-oriented programming (Erlang, C++, Java, SALSA)

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy15 Defining a programming language Syntax (grammar) Semantics (meaning)

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy16 Language syntax Defines what are the legal programs, i.e. programs that can be executed by a machine (interpreter) Syntax is defined by grammar rules A grammar defines how to make ‘sentences’ out of ‘words’ For programming languages: sentences are called statements (commands, expressions) For programming languages: words are called tokens Grammar rules are used to describe both tokens and statements

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy17 Language Semantics Semantics defines what a program does when it executes Semantics should be simple and yet allows reasoning about programs (correctness, execution time, and memory use)

C. Varela; Adapted w/permission from S. Haridi and P. Van Roy18 Approaches to semantics Programming Language Kernel Language Operational model Formal calculusAbstract machine Aid the programmer in reasoning and understanding Mathematical study of programming (languages) -calculus, predicate calculus,  -calculus Aid to the implementer Efficient execution on a real machine

C. Varela19 Programming Paradigms We will cover theoretical and practical aspects of three different programming paradigms: ParadigmTheoryLanguages Functional Programming Lambda CalculusOz Haskell Concurrent Programming Actor ModelSALSA Erlang Logic ProgrammingFirst-Order Logic Horn Clauses Prolog Oz Each paradigm will be evaluated with a Programming Assignment (PA) and an Exam. Two highest PA grades count for 40% of total grade. Lowest PA grade counts for 10% of the total grade. Two highest Exam grades count for 40% of total grade. Lowest Exam grade counts for 10% of the total grade.

C. Varela20 Lambda Calculus (PDCS 2) alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer Polytechnic Institute September 1, 2015

C. Varela21 Mathematical Functions Take the mathematical function: f(x) = x 2 f is a function that maps integers to integers: f: Z  Z We apply the function f to numbers in its domain to obtain a number in its range, e.g.: f(-2) = 4 Function Domain Range

C. Varela22 Function Composition Given the mathematical functions: f(x) = x 2, g(x) = x+1 f  g is the composition of f and g: f  g (x) = f(g(x)) f  g (x) = f(g(x)) = f(x+1) = (x+1) 2 = x 2 + 2x + 1 g  f (x) = g(f(x)) = g(x 2 ) = x Function composition is therefore not commutative. Function composition can be regarded as a (higher-order) function with the following type:  : (Z  Z) x (Z  Z)  (Z  Z)

C. Varela23 Lambda Calculus (Church and Kleene 1930’s) A unified language to manipulate and reason about functions. Given f(x) = x 2 x. x 2 represents the same f function, except it is anonymous. To represent the function evaluation f(2) = 4, we use the following -calculus syntax: ( x. x 2 2)  2 2  4

C. Varela24 Lambda Calculus Syntax and Semantics The syntax of a -calculus expression is as follows: e ::=vvariable | v.efunctional abstraction |(e e)function application The semantics of a -calculus expression is called beta-reduction: ( x.E M)  E{M/x} where we alpha-rename the lambda abstraction E if necessary to avoid capturing free variables in M.

C. Varela25 Currying The lambda calculus can only represent functions of one variable. It turns out that one-variable functions are sufficient to represent multiple-variable functions, using a strategy called currying. E.g., given the mathematical function:h(x,y) = x+y of typeh: Z x Z  Z We can represent h as h’ of type:h’: Z  Z  Z Such that h(x,y) = h’(x)(y) = x+y For example, h’(2) = g, where g(y) = 2+y We say that h’ is the curried version of h.

C. Varela26 Function Composition in Lambda Calculus S: x.(s x) (Square) I: x.(i x)(Increment) C: f. g. x.(f (g x))(Function Composition) ((C S) I) (( f. g. x.(f (g x)) x.(s x)) x.(i x))  ( g. x.( x.(s x) (g x)) x.(i x))  x.( x.(s x) ( x.(i x) x))  x.( x.(s x) (i x))  x.(s (i x)) Recall semantics rule: ( x.E M)  E{M/x} Recall semantics rule: ( x.E M)  E{M/x}

C. Varela27 Free and Bound Variables The lambda functional abstraction is the only syntactic construct that binds variables. That is, in an expression of the form: v.e we say that free occurrences of variable v in expression e are bound. All other variable occurrences are said to be free. E.g., ( x. y.(x y) (y w)) Free Variables Bound Variables

C. Varela28  -renaming Alpha renaming is used to prevent capturing free occurrences of variables when reducing a lambda calculus expression, e.g., ( x. y.(x y) (y w))  y.((y w) y) This reduction erroneously captures the free occurrence of y. A correct reduction first renames y to z, (or any other fresh variable) e.g., ( x. y.(x y) (y w))  ( x. z.(x z) (y w))  z.((y w) z) where y remains free.

C. Varela29 Order of Evaluation in the Lambda Calculus Does the order of evaluation change the final result? Consider: x.( x.(s x) ( x.(i x) x)) There are two possible evaluation orders: x.( x.(s x) ( x.(i x) x))  x.( x.(s x) (i x))  x.(s (i x)) and: x.( x.(s x) ( x.(i x) x))  x.(s ( x.(i x) x))  x.(s (i x)) Is the final result always the same? Recall semantics rule: ( x.E M)  E{M/x} Recall semantics rule: ( x.E M)  E{M/x} Applicative Order Normal Order

C. Varela30 Church-Rosser Theorem If a lambda calculus expression can be evaluated in two different ways and both ways terminate, both ways will yield the same result. e e 1 e 2 e’ Also called the diamond or confluence property. Furthermore, if there is a way for an expression evaluation to terminate, using normal order will cause termination.

C. Varela31 Order of Evaluation and Termination Consider: ( x.y ( x.(x x) x.(x x))) There are two possible evaluation orders: ( x.y ( x.(x x) x.(x x)))  ( x.y ( x.(x x) x.(x x))) and: ( x.y ( x.(x x) x.(x x)))  y In this example, normal order terminates whereas applicative order does not. Recall semantics rule: ( x.E M)  E{M/x} Recall semantics rule: ( x.E M)  E{M/x} Applicative Order Normal Order

C. Varela32 Combinators A lambda calculus expression with no free variables is called a combinator. For example: I: x.x (Identity) App: f. x.(f x)(Application) C: f. g. x.(f (g x))(Composition) L: ( x.(x x) x.(x x))(Loop) Cur: f. x. y.((f x) y)(Currying) Seq: x. y.( z.y x)(Sequencing--normal order) ASeq: x. y.(y x)(Sequencing--applicative order) where y denotes a thunk, i.e., a lambda abstraction wrapping the second expression to evaluate. The meaning of a combinator is always the same independently of its context.

C. Varela33 Combinators in Functional Programming Languages Most functional programming languages have a syntactic form for lambda abstractions. For example the identity combinator: x.x can be written in Oz as follows: fun {$ X} X end in Haskell as follows: \x -> x and in Scheme as follows: (lambda(x) x)

C. Varela34 Currying Combinator in Oz The currying combinator can be written in Oz as follows: fun {$ F} fun {$ X} fun {$ Y} {F X Y} end It takes a function of two arguments, F, and returns its curried version, e.g., {{{Curry Plus} 2} 3}  5

C. Varela35 Exercises 1.PDCS Exercise (page 31). 2.PDCS Exercise (page 31). 3.PDCS Exercise (page 31). 4.PDCS Exercise (page 31). 5.Define Compose in Haskell. Demonstrate the use of curried Compose using an example.