The Evolution of Programming Languages Day 2 Lecturer: Xiao Jia The Evolution of PLs1.

Slides:



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

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.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
Functional Programming Languages
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
ISBN Chapter 15 Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages Introduction to.
CSC321: Programming Languages14-1 Programming Languages Tucker and Noonan Chapter 14: Functional Programming 14.1 Functions and the Lambda Calculus 14.2.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
ISBN Chapter 15 Functional Programming Languages.
Cs776 (Prasad)L15strm1 Reasoning with Functional Programs Optimization by source to source transformation Well-founded induction Streams : Infinite lists.
ISBN Chapter 15 Functional Programming Languages.
CS 2104 : Prog. Lang. Concepts. Functional Programming I Lecturer : Dr. Abhik Roychoudhury School of Computing From Dr. Khoo Siau Cheng’s lecture notes.
Functional Programming in Scheme
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
Scheme & Functional Programming. ( ) >> 64 ( ) >> 666 (* ) >> 1200 (+ (* 3 5) (- 10 6)) >> 19.
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
Chapter 9: Functional Programming in a Typed Language.
Functional Programming in Scheme and Lisp.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Chapter Fifteen: Functional Programming Languages Lesson 12.
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
1 Chapter 15 © 2002 by Addison Wesley Longman, Inc Introduction - The design of the imperative languages is based directly on the von Neumann architecture.
ISBN Chapter 15 Functional Programming Languages.
COMP313A Functional Programming (1)
Dr. Philip Cannata 1 Programming Languages Chapter 14 – Functional Programming – Lisp.
The “Beauty” of Scheme: Programs as Proofs Q: Is '(abc 123) a list? A: Yes Proof:  '(abc 123) = (cons 'abc (cons 123 '()))  '() is a list, so (cons 123.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
A Short History of PL's (MacLennan 1999) “Zeroth Generation” (1940's-50's): machine language / assembly: if/then, read/write, store, goto
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
ISBN Chapter 15 Functional Programming Languages.
Functional Programming
Type Checking and Type Inference
Functional Programming Languages
Additional Scheme examples
Functional Programming Languages
Chapter 15 :Functional Programming Languages
Functional Programming Languages
Functional Programming
History of Computing – Lisp
ML: a quasi-functional language with strong typing
PPL Lazy Lists.
Chapter 15 – Functional Programming Languages
Closures and Streams cs784(Prasad) L11Clos
COP4020 Programming Languages
Functional Programming Languages
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
The Metacircular Evaluator
Lecture #9 מבוא מורחב.
Functional Programming Languages
6.001 SICP Variations on a Scheme
COP4020 Programming Languages
15.2 Mathematical Functions
topics interpreters meta-linguistic abstraction eval and apply
Functional Programming Languages
Dispatch on Type (one-less x) => x-1 if x is a <number>
Presentation transcript:

The Evolution of Programming Languages Day 2 Lecturer: Xiao Jia The Evolution of PLs1

The Functional Paradigm The Evolution of PLs2

High Order Functions zeroth order: only variables and constants first order: function invocations, but results and parameters are zeroth order n-th order: results and parameters are (n- 1)-th order high order: n >= 2 The Evolution of PLs3

LISP f(x, y)  (f x y) a + b  (+ a b) a – b – c  (- a b c) (cons head tail) (car (cons head tail))  head (cdr (cons head tail))  tail The Evolution of PLs4

It’s straightforward to build languages and systems “on top of” LISP (LISP is often used in this way) The Evolution of PLs5

Lambda f = λx.x 2  (lambda (x) (* x x)) ((lambda (x) (* x x)) 4)  16 The Evolution of PLs6

Dynamic Scoping int x = 4; f() { printf(“%d”, x); } main() { int x = 7; f(); } The Evolution of PLs7 Static Scoping Dynamic Scoping Describe a situation in which dynamic scoping is useful

Interpretation Defining car (cond ((eq (car expr) ’car) (car (cadr expr)) ) … The Evolution of PLs8

Scheme corrects some errors of LISP both simpler and more consistent (define factorial (lambda (n) (if (= n 0) 1 (* n (factorial (- n 1)))))) The Evolution of PLs9

Factorial with actors (define actorial (alpha (n c) (if (= n 0) (c 1) (actorial (- n 1) (alpha (f) (c (* f n))))))) The Evolution of PLs10

Static Scoping (define n 4) (define f (lambda () n)) (define n 7) (f) The Evolution of PLs11 LISP: 7 Scheme: 4

Example: Differentiating The Evolution of PLs12

Example: Differentiating The Evolution of PLs13 (define derive (lambda (f dx) (lambda (x) (/ (- (f (+ x dx)) (f x)) dx)))) (define square (lambda (x) (* x x))) (define Dsq (derive sq 0.001)) -> (Dsq 3) 6.001

SASL St. Andrew’s Symbolic Language The Evolution of PLs14

Lazy Evaluation nums(n) = n::nums(n+1) second (x::y::xs) = y second(nums(0)) = second(0::nums(1)) = second(0::1::nums(2)) = 1 The Evolution of PLs15 infinite list

Lazy Evaluation if x = 0 then 1 else 1/x In C: X && Y  if X then Y else false X || Y  if X then true else Y if (p != NULL && p->f > 0) … The Evolution of PLs16

Standard ML (SML) MetaLanguage The Evolution of PLs17

Function Composition - infix o; - fun (f o g) x = g (f x); val o = fn : (’a -> ’b) * (’b -> ’c) -> ’a -> ’c - val quad = sq o sq; val quad = fn : real -> real - quad 3.0; val it = 81.0 : real The Evolution of PLs18

List Generator infix --; fun (m -- n) = if m < n then m :: (m+1 -- n) else [];  [1,2,3,4,5] : int list The Evolution of PLs19

Sum & Products fun sum [] = 0 | sum (x::xs) = x + sum xs; fun prod [] = 1 | prod (x::xs) = x * prod xs; sum (1 -- 5);  15 : int prod (1 -- 5);  120 : int The Evolution of PLs20

Declaration by cases fun fac n = if n = 0 then 1 else n * fac(n- 1); fun fac 0 = 1 | fac n = n * fac(n-1); The Evolution of PLs21