Principles of Programming Languages (2016F)

Similar documents
Aspect-Oriented Programming

Com S 541. Programming Languages I

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

CS 314 Principles of Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

MIDTERM EXAMINATION - CS130 - Spring 2005

Functional Languages. Hwansoo Han

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Functional Programming. Pure Functional Programming

Functional Programming. Big Picture. Design of Programming Languages

Concepts of Programming Languages

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

CS 242. Fundamentals. Reading: See last slide

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Implementing evolution: Aspect-Oriented Programming

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Pierce Ch. 3, 8, 11, 15. Type Systems

CS 415 Midterm Exam Spring SOLUTION

Programming Languages

Organization of Programming Languages CS3200/5200N. Lecture 11

4/19/2018. Chapter 11 :: Functional Languages

Chapter 15. Functional Programming Languages

Contents. Chapter 1 SPECIFYING SYNTAX 1

Functional Programming Languages (FPL)

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

Comp 311: Sample Midterm Examination

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

CMSC330 Spring 2008 Final Exam

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

Chapter 15 Functional Programming Languages

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Semester Review CSC 301

Polymorphism and Type Inference

Chapter 11 :: Functional Languages

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

COP4020 Spring 2011 Midterm Exam

CSE3322 Programming Languages and Implementation

(Func&onal (Programming (in (Scheme)))) Jianguo Lu

CMSC 331 Final Exam Section 0201 December 18, 2000

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Introduction to Functional Programming in Haskell 1 / 56

CSE3322 Programming Languages and Implementation

Seminar in Programming Languages

Functional Programming and Haskell

Imperative languages

CS3360 Design and Implementation of Programming Languages Final Exam May 16, pm to 12:45pm (2 hour and 40 minutes) NAME:

Functional Logic Programming Language Curry

Programming Languages, Summary CSC419; Odelia Schwartz

CMSC 330: Organization of Programming Languages. Administrivia

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

Introducing Wybe a language for everyone

CS 415 Midterm Exam Spring 2002

Chapter 15. Functional Programming Languages ISBN

Programming language design and analysis

Chapter 3 (part 3) Describing Syntax and Semantics

Functional Programming Lecture 1: Introduction

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

CSE3322 Programming Languages and Implementation

Types and Type Inference

New Programming Paradigms

Example Scheme Function: equal

Review and Recursion

CS 314 Principles of Programming Languages

Types and Type Inference

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Type Systems, Type Inference, and Polymorphism

Introduction to SML Getting Started

CMSC 330: Organization of Programming Languages. Operational Semantics

Formal Systems and their Applications

COSE212: Programming Languages. Lecture 0 Course Overview

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Principles of Programming Languages

CSCI-GA Final Exam

NOTE: Answer ANY FOUR of the following 6 sections:

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Types, Type Inference and Unification

The design of a programming language for provably correct programs: success and failure

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Verified compilers. Guest lecture for Compiler Construction, Spring Magnus Myréen. Chalmers University of Technology

MIDTERM EXAM (Solutions)

CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Static semantics. Lecture 3-6: Semantics. Attribute grammars (2) Attribute grammars. Attribute grammars example. Dynamic semantics

F28PL1 Programming Languages. Lecture 11: Standard ML 1

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP)

LECTURE 16. Functional Programming

Programming Paradigms

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Transcription:

03-60-440 Principles of Programming Languages (2016F) Jianguo Lu School of Computer Science University of Windsor

It is about programming languages This course involves several programming languages: Scheme (Functional) Prolog (Logic) AspectJ XSLT This course is more than excursions to various languages 1

It is about the fundamental question What is a programming language? 2

What is a program It is a sequence of statements! Imperative paradigm It is a group of interacting objects! OO paradigm It is a function! Functional paradigm It is a set of rules! Logic paradigm 3

It is about classification, history, styles (paradigms), concepts common in many languages Programming language classification and history Syntax and semantics of programming languages Syntax is covered in 60-214. Won t repeat it. Axiomatic semantics Paradigms of programming Imperative and declarative programming OOP: Abstract data type, inheritance, polymorphism, AOP (Aspect Oriented Programming) Functional programming, lambda calculus, Scheme, MapReduce XML Programming: XSLT Logic programming Concepts in programming languages Side-effect, type checking, strong typing, overload, override, coercion, callby-value, call-by-reference, polymorphism, multiple inheritance, generics, dynamic binding, imperative and declarative programming, 4

Language description: Axiomatic Semantics Language description: Syntax (covered in 03-60-214), semantics. Formal methods to describe semantics: operational, denotational, axiomatic Axiomatic semantics is also used to prove the correctness of programs Java has Assertion to describe the meaning of program Axiomatic semantics uses a formal system (axiomatic system) to describe the meaning of programs Axiom {P(E/x)} x = E Inference rule {P} For example, {x=0} x= x+1; y= x; { x=1and y=1} {P1}S1{P2},{P2}S2{P3} {P1}S1;S2{P3} 5

Imperative programming Describes computation in terms of a program state and statements that change the program state. Imperative programs are a sequence of commands for the computer to perform. The hardware implementation of almost all computers is imperative. Von Neumann machine In contrast to declarative programming Insertion sort in Java void insertionsort (int[ ] A) { int j; for (int i = 1; i < A.length; i++) { int a = A[i]; } } for (j = i -1; j >=0 && A[j] > a; j- -) A[j + 1] = A[j]; A[j + 1] = a; 6

Functional Programming Functional programming treats computation as the evaluation of mathematical functions. It is more heavily used in academia than in industry. The strength of a functional paradigm is the removal of side-effects during computation. This has uses in program verification, for checking the correctness of programs, program optimisation. One particular use in program optimisation is to transform programs for parallel programming. The idea is used in Map-Reduce programming, widely used to process big data. z = f(sqrt(2), sqrt(2)); we can factor out sqrt(2) and write s = sqrt(2); z = f(s, s); 7

Functional Programming vs. Imperative Programming In strict functional programming, there is no explicit memory allocation and no explicit variable assignment, so side effects of function evaluation are eliminated. Looping is accomplished through the more general functional construct of recursion. Sort in ML: fun insertsort [] = [] end; insertsort (x::xs) = let fun insert (x:real, []) = [x] insert (x:real, y::ys) = if x<=y then x::y::ys in insert(x, insertsort xs) else y::insert(x, ys) 8

sort function defined in Scheme language (define (insert x l) ( if (null? l) (list x) (if (<= x (car l)) (cons x l) (cons (car l) (insert x (cdr l)))))) (define (isort l) (if (null? l) () (insert (car l) (isort (cdr l))))) 9

Map-reduce programming Derived from functional programming Find wide applications in big data processing Google, Yahoo, Distribute operations over multiple machines Hadoop 10

Logic Programming Program is a set of facts and rules. Based on first-order predicate logic Original motivation: study of mechanical theorem proving Used in Artificial Intelligence, databases, expert systems. Insertion sort in prolog isort([ ],[ ]). isort([x UnSorted],AllSorted) :- isort(unsorted,sorted), insert(x,sorted,allsorted). insert(x, [ ], [X]). insert(x, [Y L], [X, Y L]) :- X =< Y. insert(x, [Y L], [Y IL]) :- X > Y, insert(x, L, IL). 11

OOP Abstract Data Type Multiple inheritance in Java Polymorphism Overloading Generics Dynamic binding 12

Distributed Object and Object Persistency from www.agiledata.org 13

AOP Aspect Oriented Programming A new programming paradigm Example void transfer(account fromaccount, Account toaccount, int amount) { } if (fromaccount.getbalance() < amount) { } throw new InsufficientFundsException(); fromaccount.withdraw(amount); toaccount.deposit(amount); However, in a real-world banking application, this transfer method is not adequate. We need to: Include security checks to verify that the current user has the authorization to perform this operation. Enclose the operation in a database transaction in order to prevent accidental data loss. Log the operation to the system log. And so on. 14

Aspect Oriented Programming void transfer(account fromaccount, Account toaccount, int amount) { if (!getcurrentuser().canperform(op_transfer)) { throw new SecurityException(); } if (fromaccount.getbalance() < amount) { throw new InsufficientFundsException(); } Transaction tx = database.newtransaction(); try { fromaccount.withdraw(amount); toacount.deposit(amount); tx.commit(); systemlog.logoperation(op_transfer, fromaccount, toaccount, amount); } catch(exception e) { tx.rollback(); } } The code has lost its elegance and simplicity various new concerns tangled with the basic functionality (business logic concern). The transactions, security, logging, etc. all exemplify crosscutting concerns. Implementation of crosscutting concerns are scattered across numerous methods. Change of the implementation would require a major effort. Solution: Separate different concerns. 15

XSLT It is an XML-based language Used to transform XML; The language itself is in XML. It is a declarative language Does not list an imperative sequence of actions to perform in a stateful environment, Consists of a template rules, specifies what to add to the result. XSLT XML XSLT processor 16

Implementation techniques of programming languages A continuation from 214 attribute grammar Parsing result type checking Type inference rules and their implementations Garbage collection How to manage memory more efficiently Follow the text in the dragon book 17

Robert Sabastia, Von Roy &Haridi, John Mitchell, Benjemin Pierce, Glynn Winskel, Kenneth Louden, Seyed Roosta, Pratt & Zelkowitz 18

Bonus assignment: (8%) Count method calls in JDK(Java Development Kit) Parsing real large programs (7000+ files) Get all the details of the programs Using JDT (Eclipse Java Development Tool) 19

Times and places Course web site: http://cs.uwindsor.ca/~jlu/440 Office: 5111 Lambton Tower Email: jlu at uwindsor Office hours: Monday & Wednesday 2:30-3:30 Midterm: October 24 Examinations are closed books and closed notes. The only valid excuse for missing an exam is a documented medical emergency. A missed exam without medical documentation will result in a mark of zero. 20

Marking scheme Assignments 15 % Midterm 35 % Final exam 50 % 21

Three assignments (15 %): (5%) Aspect oriented programming; (5%) Functional and Logic programming; (5%) XSLT programming; Bonus assignment (8%) Generate parse tree of real Java programs. TA will help you with your assignments There is no text book. Class attendance is important! Exams will cover whatever is taught in class; Exams will cover the assignments. 22