NCCU 資訊碩專班 Advanced Programming Languages 高等程式語言 資科系陳恭副教授. Instructor: Spring Lecture 6: Functional Programming, Lisp, Scheme-1 修訂版

Size: px
Start display at page:

Download "NCCU 資訊碩專班 Advanced Programming Languages 高等程式語言 資科系陳恭副教授. Instructor: Spring Lecture 6: Functional Programming, Lisp, Scheme-1 修訂版"

Transcription

1 NCCU 資訊碩專班 Advanced Programming Languages 高等程式語言 Instructor: 資科系陳恭副教授 Spring 2006 Lecture 6: Functional Programming, Lisp, Scheme-1 修訂版 1

2 Outline Functional Programming Scheme Lisp History and Motivation Scheme Programming Basics 2

3 What is a Function? y = 2 * x x a 2 * x twice(x) = 2 * x twice x = 2 * x (Prefix Notation) 3

4 Partial and Total Functions f(x) g(x) x Total function: f(x) has a value for every x Partial function: g(x) does not have a value for every x 4

5 Functional Languages λ 5

6 Functional Programming Correctness, Clarity > (Machine) Efficiency Based on sound theoretical frameworks (e.g., the lambda calculus) 6

7 Imperative Style vs Functional Style Imperative programs Description of WHAT is to be computed is inter-twined with HOW it is to be computed. The latter involves organization of data and the sequencing of instructions. Functional Programs Separates WHAT from HOW. The former is programmer s responsibility; the latter is interpreter s/compiler s responsibility. 7

8 GCD : functional vs imperative fun gcd(m,n) = if m=0 then n else gcd(n mod m, m); function gcd(m,n: int) : int; var pm:int; begin while m<>0 do begin pm := m; m := n mod m; n := pm end; return n end; 8

9 Functional A mathematical function always returns the same value for the same inputs: f(x) = 2x+3 f(3) = 9 (always) f(3) = 9 (still) This is the definition of a function 9

10 Values never change Once we assign a value it is always the same it never changes x = 6 then x always equals 6 in this context 10

11 No change and a call to a function never changes anything else x = y = f(x)+f(x) The same as y= 2* f(x) Not true in C/C++ Imperative languages int f(int i) { x++; return 5*I; } 11

12 Referential Transparency The only thing that matters about an expression is its value, and any sub-expression can be replaced by any other expression equal in value. The value of an expression is independent of its position only provided we remain within the scopes of the definitions which apply to the names occurring in the expression. 12

13 Functional Model is a beautiful model of computation Equals can be substituted for equals completely capable can solve any computable problem with it easy to reason about but it does make programming some things awkward. Assignments I/O 13

14 Pure or Impure Functional Programming Functions are first class values a data type is first class if it can be used anywhere, passed to and returned from functions, assigned to variables May also have imperative constructs Examples: Lisp, Scheme, ML, Erlang Pure functional languages have no implicit sideeffects or other imperative features Examples: Miranda, Haskell 14

15 Historical Background of Lisp Lisp is developed in the 1950s for artificial intelligence programming. Only Fortran, COBOL available at that time Only Static data structures Arrays, Records No recursion Need dynamic data structures solving AI-related problems Related Ideas In the 1950s Newell, Shaw, and Simon (at Carnegie institute of technology and the Rand Corporation) developed many of the ideas of list processing in the IPL family of programming languages FLPL, the Fortran List-Processing Language 15

16 John McCarthy Published paper in ACM Titled Recursive Functions of Symbolic Expressions and Their computation by Machine, Part 1, 1960 課程網站資源區下載閱讀 (Part 2 was never published) 16

17 New Ideas The Structured Conditional Statement: A Lisp conditional is an if-then-else construct instead as a statement that relied on the branch instruction in the underlying hardware as was common in other languages of the time. The Function as a Data Type: In Lisp, functions are a data type just like integers, strings, etc., and have a literal representation, can be stored in variables, can be passed as arguments, and so on. Recursion. Lisp was the first programming language to support recursion, even though it was useful in mathematics before that. 17

18 Ideas Variables as Implicit Pointers: I know you might not like pointers very much, so you will like that in Lisp all variables are effectively implicit pointers. This means that pointers need not be handled explicitly by the programmer! Values are what have types, not variables, and assigning or binding variables means copying pointers, instead of what they point to. Garbage-collection: Other languages of the time let old variables clutter up memory, but Lisp cleans memory up. Expressions: FORTRAN and most succeeding languages like C++ distinguish between expressions and statements. In Lisp there is no distinction. 18

19 Lisp = Lots of infuriating and silly parenthesis John McCarthy invented 1958 The first Lisp interpreter was on a IBM 704 in 1959 by Steve Russell First compiler written in Lisp in 1962 Introduced the model compilation, where compiled and interpreted functions can interact freely. The compiler was closer to modern Lisp than McCarthy and Russell s earlier code 19

20 AI Community and Lisp was mainly used in the AI Community Used to make Planner which was the language for SHRDLU SHRDLU allowed users to interact using English terms to move objects in a small blocks world Dialects InterLisp MacLisp ZetaLisp Franz Lisp Standardised By ANSI X Common Lisp or CL Most Lisp conform to. Scheme dialects MIT/GNU Scheme mzscheme PLT Scheme DrScheme IDE Standardized IEEE Scheme JScheme 20

21 Paul Graham and ViaWeb From mid-11980, Lisp market started to decline Paul Graham is a Lisp programmer and essayist Wrote about the benefits of Lisp Created ViaWeb with Lisp for users to create their own web stores. Sold to Yahoo for $50 million and renamed to Yahoo! Store. 暢銷書 Hackers and Painter ( 駭客與畫家 ) 21

22 The Scheme programming language Scheme is a functional programming language and a dialect of Lisp Scheme was the first dialect of Lisp to use lexical variable scoping (aka static scoping, as opposed to dynamic variable scoping) exclusively. Developed in 1975 by G. Sussman and G. Steele Scheme : an Interpreter for Extended Lambda Calculus 22

23 Scheme Overview Scheme is a dialect of Lisp Lisp is a large design-by-committee language Scheme was developed to simplify Lisp Scheme is interpreted REP loop Read input Evaluate the input Print the results produced by evaluation 23

24 S-expressions In LISP/Scheme, data & programs are all of the same form: S-expressions (Symbolic-expressions) an S-expression is either an atom or a list (ignore dotted pairs) Atoms numbers /2 #xa2 #b1001 characters strings Booleans #t #f symbols #\a #\Q #\space #\tab "foo" Hello Hi" "@%!?#" Dave num123 miles->km!_^_! symbols are sequences of letters, digits, and "extended alphabetic characters" + -. * / < > =!? : $ % + & ~ ^ can't start with a digit, case insensitive 24

25 S-expressions (cont.) Lists () is a list (L1 L2... Ln) is a list, where each Li is either an atom or a list for example: () (a b c d) (((((a))))) (a) ((a b) c (d e)) note the recursive definition of a list GET USED TO IT! also, get used to parentheses (LISP = Lots of Insane, Silly Parentheses) 25

26 Evaluation Evaluation of s-expressions An atom evaluates to itself Examples foo hello #t An identifier evaluates to the object that it is bound to Note that identifies are very flexible in scheme. May contain characters like?.-* and most other symbols! Examples (define a 7) a 26

27 Evaluation Evaluation of s-expressions (continued) A list applies an operator to the supplied operands (operator op1 op2 op3 ) where operator is a procedure that is applied to the supplied operands First element must evaluate to a function Recursively evaluate each argument Apply the function on the evaluated arguments Examples ( ) (* 3 5) (- 12 1) (+ (* 2 3) (/ 4 2)) 27

28 Arithmetic primitives predefined functions: + - * / quotient remainder modulo max min abs gcd lcm floor ceiling truncate round = < > <= >= many of these take a variable number of inputs ( ) 21 (max ) 8 (= 1 (-3 2) (* 1 1)) #t (< ) #t null? 28

29 Evaluation and Special Forms Consider the following Evaluate: >( ) Produces an error since 1 is not a procedure To prevent evaluation use a quote Evaluate: > ( ) Evaluate: >(quote ( )) To force evaluation use eval Evaluate: > (+ 1 2) Evaluate: >(eval (+ 1 2)) Special Forms Scheme has no reserved words. Any name can be re-defined. Scheme has special pre-defined forms however. Things like define or + or * for example. We will discuss many more examples later. 29

30 List Operations Basic data structure in Scheme is a list Four fundamental special forms for operation on lists (car x) : returns the first element of list x. An error if x is empty. (cdr x) : returns a list of the elements of list x without the first. An error if x is empty. (null? x) : returns true if x is a list and false otherwise (cons h x) : returns a list with car h and cdr x Examples: (car (1 2 3)) (car ((1 2) 3)) (cdr (1 2 3)) (cdr (1 (2 3))) (cdr (1)) (car ()) (car (cdr (car ((1 2 3) 4 5 6)))) 30

31 Decomposing a list (car (this is a list of symbols)) => this (cdr (this is a list of symbols)) => (is a list of symbols) (cdr (this that)) => (that) ; a list (cdr (singleton)) => () ; the empty list (car ()) ; run time error 31

32 Building lists (cons this (that and the other)) => (this that and the other) (cons a ()) => (a) useful shortcut: list (list a b c d e) => (a b c d e) equivalent to (cons a (cons b (cons c (cons d (cons e ()))))) 32

33 Function Declarations (define (sqr n) (* n n)) define is also special: body is not evaluated defines produces a binding: sqr is bound to the function value: (lambda (n) (* n n)) i.e. function can be unnamed. define can produce varaible bindings as well: (define x 15) ;; the symbol x becomes a variable (sqr x) =>

34 Unnamed Functions Functions are (first-class) values => functions can exist without names Defining function values: notation based on the lambda-calculus lambda-calculus: a formal system for defining recursive functions and their properties (equivalent to Turing machines) (lambda (<param-list>) <body-s-expression>) 34

35 Using Function (Procedure) Values Examples: (* 10 10) value: 100 (define (square x) (* x x)) (square 10) value: 100 (lambda (x) (* x x)) value: compound procedure ( (lambda (x) (* x x)) 10) value: 100 (define sq (lambda (x) (* x x)) ) (sq 10) value: 100 alternative form of function definition 35

36 Lambda Calculus Lambda calculus provides the mathematical foundation for functional programming A lambda expression specifies a procedure, the arguments, and the body For lambda calculus, the following rules apply Any identifier is a lambda expression If M and N are two lambda expressions, then the application of M to N is written (MN) and is also a lambda expression An abstraction, (λx. M) where x is an identifier and M is a lambda expression is also a lambda expression 36

37 Lambda Calculus In the expression (λx. M), the identifier x is said to be bound in M. Any other identifier occurring in M is said to be free. Identify the free and bound variables: (λx. (* (+ y x) (- x z))) Function evaluation amounts to substitution (or beta reduction) When an abstraction is applied to an argument, a substitution is made A substitution of expression N for variable x in M is written M[N/x] The abstraction essentially creates a new local environment which hides names from outside expressions ((λx. (* (+ y x) (- x z))) (* y z)) means (λx. (* (+ y x) (- x z))) [(* y z)/x] which means (* (+ y (* y z)) (- (* y z) z))) 37

38 Boolean valued Special Forms Basic forms include <, <=, =, >=, > AND, OR, NOT Note that each of these takes 2 or more arguments! (except for NOT) The logical comparisons work on numbers only! Examples (< 3 5) (<= 4 4) (= 5 5) (= (1) (1)) (and (< 3 5) (< 5 6)) (or (< 3 5) (not (< 6 3)) (< 2 1)) 38

39 Special Form: Control structures If-Conditional (if condition expr1 expr2) Generalized form (cond) (cond ) (pred1 expr1) (pred2 expr2) (else exprn) Needs special rule: evaluate only the successful entry if and cond are not regular functions DrScheme 支援另一種寫法 (cond [pred1 expr1] [pred2 expr2] [else exprn] ) 39

40 Cond Examples (cond ((< 2 1) 2) ((< 1 2) 1)) (cond ((< 2 1 ) 2) ((< 3 2) 3)) has value 1 is undefined (cond (diverge 1) (#t 0)) is undefined, where diverge is undefined (cond (#t 0) (diverge 1)) (cond ((<5 8) Impossible) (else Likely)) has value 0 has value Likely 40

41 Recursion (define (add1 x) (+ x 1)) ; the beginnings of Peano arithmetic (define (sub1 x) (- x 1)) (define (add x y) (if (= y 0) x (add ( (add1 x) (sub1 y)) ) ) (define (times x y) (cond ((= y 0) 0) ((= y 1) x) (else (add x (times (x (sub1 y))))) ) ) 41

42 Recursion (ii) (define (exp x y) (cond ((eq? y 0) 1) (else (times x (exp x (sub1 y)))))) better: (define (fast-exp x y) (cond (= y 0) 1) ( (even? y) (square (fast-exp x (/ y 2)))) (else (* x (fast-exp x (- y 1)))))) (define (even? n) (= (remainder n 2) 0)) ; defining a predicate 42

43 List Operations (Revisited) Other useful list operations (length x) : returns the length of list x (reverse x) : returns a list of the elements in x in reverse order (append x y) : returns a list of elems in list x followed by elements from list y (member e x) : returns a sub-list of x beginning with e (list a b c ) : returns a list of the specified elements Each of these operations can be written using only the 4 fundamental list operations and conditionals 43

44 Polymorphism Polymorphic functions can be applied to arguments of different types function length is polymorphic: (length (1 2 3)) value: 3 (length (a b c)) value: 3 (length ((a) b (c d))) value: 3 function zero? is not polymorphic (monomorphic): (zero? 10) value: #t (zero? a) error: object a is not the correct type 44

45 Useful Type Checking Predicates functions that return a true/false value are called predicate functions zero? positive? negative? odd? even? Null? (odd? 5) #t (positive? (- 4 5)) #f (null? (1 2)) () or #f Sometimes it is necessary to know what a thing is (list? x) : true if x is a list and false otherwise (procedure? x) : true if x is a procedure and false otherwise (number? x) : true if x is a number and false otherwise (symbol? x) : true if x is a symbol and false otherwise (string? x) : true if x is a string and false otherwise (boolean? x) : true if x is a boolean and false otherwise (char? x) : true if x is a character and false otherwise 45

46 Type predicates type predicates return true or false depending on the type of the argument. (define doubler (lambda (x) (cond ((number? x) (+ x x)) ((string? x) (string-append x x) (else (cons x x))))) (doubler 3) => 6 (doubler hi dave ) => hi davehi dave 46

47 Type predicates type predicates return true or false depending on the type of the argument. DrScheme 支援另一種寫法 (define doubler (lambda (x) (cond [(number? x) (+ x x)) ] [(string? x) (string-append x x)] [else (cons x x)] ))) (doubler 3) => 6 (doubler hi dave ) => hi davehi dave 47

48 List Operations Revisited Can roll our own list operations (define (my-length x) x) (cond (cond ((null? x) x) 0) 0) (else (else (+ (+ 1 (my-length (cdr (cdr x)))))) (define (my-append x y) y) (cond (cond ((null? x) x) y) y) (else (else (cons (cons (car (car x) x) (my-append (cdr (cdr x) x) y))))) (define (define (my-reverse (my-reverse x) x) (cond (cond ((null? ((null? x) x) x) x) (else (else (my-append (my-append (my-reverse (my-reverse (cdr (cdr x)) x)) (list (list (car (car x)))))) x)))))) 48

49 Tracing function evaluation: Substitution Model (define (length l) (if (null? l) 0 (+ 1 (length (cdr l))) ) ) (length (a b c)) L (a b c) evaluates to: (if (null? (a b c)) 0 (+ 1 (length (cdr (a b c)))) ) evaluates to: (+ 1 (length (cdr (a b c)))) evaluates to: (+ 1 (length (b c))) evaluates to: (+ 1 (if (null? (b c)) 0 (+ 1 (length (cdr (b c)))) )) evaluates to: (+ 1 (+ 1 (length (cdr (b c))) )) evaluates to: (+ 1 (+ 1 (length (c)) ) ) evaluates to: (+ 1 (+ 1 (if (null? (c)) 0 (+ 1 (length (cdr (c)))) ))) evaluates to: (+ 1 (+ 1 (+ 1 (length (cdr (c))) ))) evaluates to: (+ 1 (+ 1 (+ 1 (length ()) ))) evaluates to: (+ 1 (+ 1 (+ 1 (if (null? ()) 0 (+ 1 (length (cdr ()))) )))) evaluates to: (+ 1 (+ 1 (+ 1 0))) evaluates to: (+ 1 (+ 1 1)) evaluates to: (+ 1 2) evaluates to: 3 49

50 Practice with Scheme Programming Write a factorial program in Scheme (define (factorial x) x) (if (if (= (= x 1) 1) 1 (* (* x (factorial (- (- x 1))))) Write a fibonacci program in Scheme (define (fib (fib x) x) (cond (cond ((= ((= x 0) 0) 0) 0) ((= ((= x 1) 1) 1) 1) (else (else (+ (+ (fib (fib (- (- x 1)) 1)) (fib (fib (- (- x 2)))))) 50

51 Tree Recursion (fib 5) (fib 3) (fib 4) Inefficient! (fib 1) (fib 2) (fib 2) (fib 3) (fib 0) (fib 1) (fib0)(fib 1) (fib 1) (fib 2) (fib 0)(fib 1) 51

52 Practice with Scheme Programming Write a fast fibonacci program in Scheme (define (fib-helper fib-i-minus-one ith-fib i n) n) (cond (cond ((= ((= i n) n) ith-fib) (else (else (fib-helper ith-fib (+ (+ ith-fib fib-i-minus-one) (+ (+ i 1) 1) n)))) n)))) (define (fib (fib n) n) (fib-helper n)) n)) 52

53 Tail-Recursive Fibonacci (define (fib (fib x) x) (cond (cond ((= ((= x 0) 0) 0) 0) ((= ((= x 1) 1) 1) 1) (else (else (+ (+ (fib (fib (- (- x 1)) 1)) (fib (fib (- (- x 2)))))) (define Fibonacci (lambda (n) (Fibonacci-kernel 0 1 n))) (define Fibonacci-kernel ; fib(n-2), fib(n-1) (lambda (current next remaining) (if (= 0 remaining) current (Fibonacci-kernel next (+ current next) (- remaining 1)) ) ) ) 53

54 Practice with Scheme Programming Write a function to sum elements of a list (define (sum (sum x) x) (cond (cond ((null? x) x) 0) 0) (else (else (+ (+ (car (car x) x) (sum (sum (cdr (cdr x)))))) Write a function to return the nth element of a list (define (nth (nth x n) n) (cond (cond ((= ((= n 0) 0) (car (car x)) x)) (else (else (nth (nth (cdr (cdr x) x) (- (- n 1))))) 54

55 Recursion vs. Iteration (Loops) Tail Recursion is as efficient as looping. 55

56 Just the factorial... (define (fact n) (if (= n 0) 1 (* n (fact (- n 1))) ) ) Recursion and runtime stack 56

57 So to calculate... Time (fact 5) (* 5 (fact 4)) (* 5 (* 4 (fact 3))) (* 5 (* 4 (* 3 (fact 2)))) (* 5 (* 4 (* 3 (* 2 (fact 1))))) (* 5 (* 4 (* 3 (* 2 (* 1 (fact 0)))))) Stack (space) (define (fact n) (if (= n 0) 1 (* n (fact (- n 1))) ) ) 57

58 But we could use tail recursion a tail-recursive function is one in which the recursive call occurs last (define (tailfact n result) // help function (if (= n 0) result Accumulating parameter (tailfact (- n 1) (* n result)))) (define (fact n) (tailfact n 1)) 58

59 Analysis (fact 5) (tailfact 5 1) (tailfact 4 5) (tailfact 3 20) (tailfact 2 60) (tailfact 1 120) (tailfact 0 120) 120 Stack Time 59

60 But how does it work? Tail recursion requires two elements The tail recursive module must terminate with a recursive call that leaves no work on the stack to finish up. Any storage then must be done in the parameter list as opposed to the stack The interpreter or compiler must be designed to recognize tail recursion and handle it appropriately 60

61 Tail recursion is logically equivalent to a loop! Just put a goto in place of the recursive call!!! 61

62 Rewrite in C int tailfact(int n, int result) { if(n == 0) { } else { } return result; return tailfact(n - 1, result * n); Recall that this function will be called like: tailfact(5,1) 62

63 Put arg calcs into assignments int tailfact(int n, int result) { if(n == 0) return result; else { result = result * n; return tailfact(n - 1, result); } 63

64 Put arg calcs into assignments int tailfact(int n, int result) { if(n == 0) return result; else { result = result * n; n = n - 1; return tailfact(n, result); } 64

65 Substitute goto beginning in place of recursive call int tailfact(int n, int result) { beginning: if(n == 0) return result; else { result = result * n; n = n - 1; goto beginning; } 65

66 Eliminate the goto int tailfact(int n, int result) { while(1) { if(n == 0) return result; result = result * n; n = n - 1; } return ERROR; } 66

CSC 533: Programming Languages. Spring 2015

CSC 533: Programming Languages. Spring 2015 CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme S-expressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages. Programming Language Paradigm CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

Chapter 15. Functional Programming Languages

Chapter 15. Functional Programming Languages Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

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

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Programming Language Pragmatics

Programming Language Pragmatics Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7 Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

More information

CSC324 Functional Programming Efficiency Issues, Parameter Lists

CSC324 Functional Programming Efficiency Issues, Parameter Lists CSC324 Functional Programming Efficiency Issues, Parameter Lists Afsaneh Fazly 1 January 28, 2013 1 Thanks to A.Tafliovich, P.Ragde, S.McIlraith, E.Joanis, S.Stevenson, G.Penn, D.Horton 1 Example: efficiency

More information

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in

More information

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

An Introduction to Scheme

An Introduction to Scheme An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification

More information

FP Foundations, Scheme

FP Foundations, Scheme FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages

More information

Scheme: Expressions & Procedures

Scheme: Expressions & Procedures Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XIII March 2 nd, 2006 1 Roadmap Functional Languages Lambda Calculus Intro to Scheme Basics Functions Bindings Equality Testing Searching 2 1 Functional Languages

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Programming Languages

Programming Languages Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,

More information

Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.

More information

SOFTWARE ARCHITECTURE 6. LISP

SOFTWARE ARCHITECTURE 6. LISP 1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

More information

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 3 2. Applications... 3 3. Examples... 4 4. FPL Characteristics:... 5 5. Lambda calculus (LC)... 6 5.1. LC expressions forms... 6 5.2. Semantic of

More information

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G. Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

More information

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme

More information

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

Recursive Functions of Symbolic Expressions and Their Application, Part I

Recursive Functions of Symbolic Expressions and Their Application, Part I Recursive Functions of Symbolic Expressions and Their Application, Part I JOHN MCCARTHY Review: Amit Kirschenbaum Seminar in Programming Languages Recursive Functions of Symbolic Expressions and Their

More information

Control in Sequential Languages

Control in Sequential Languages CS 242 2012 Control in Sequential Languages Reading: Chapter 8, Sections 8.1 8.3 (only) Section 7.3 of The Haskell 98 Report, Exception Handling in the I/O Monad, http://www.haskell.org/onlinelibrary/io-13.html

More information

SCHEME AND CALCULATOR 5b

SCHEME AND CALCULATOR 5b SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

More information

Example Scheme Function: equal

Example Scheme Function: equal ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to

More information

SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012

SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012 SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually

More information

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

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

More information

A Brief Introduction to Scheme (I)

A Brief Introduction to Scheme (I) A Brief Introduction to Scheme (I) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Scheme Scheme I p.1/44 Scheme: Feature Set A

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages. Lecture LISP Programming Language An Introduction Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

More information

An introduction to Scheme

An introduction to Scheme An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize

More information

Imperative languages

Imperative languages Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered

More information

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

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work

More information

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

4/19/2018. Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen

More information

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

Notes on Higher Order Programming in Scheme. by Alexander Stepanov by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

More information

User-defined Functions. Conditional Expressions in Scheme

User-defined Functions. Conditional Expressions in Scheme User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment

More information

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

(Func&onal (Programming (in (Scheme)))) Jianguo Lu (Func&onal (Programming (in (Scheme)))) Jianguo Lu 1 Programming paradigms Func&onal No assignment statement No side effect Use recursion Logic OOP AOP 2 What is func&onal programming It is NOT what you

More information

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson Streams, Delayed Evaluation and a Normal Order Interpreter CS 550 Programming Languages Jeremy Johnson 1 Theme This lecture discusses the stream model of computation and an efficient method of implementation

More information

Programming Systems in Artificial Intelligence Functional Programming

Programming Systems in Artificial Intelligence Functional Programming Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview

More information

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

Functional abstraction

Functional abstraction Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

CS 314 Principles of Programming Languages. Lecture 16

CS 314 Principles of Programming Languages. Lecture 16 CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

More information

Chapter 15. Functional Programming Languages ISBN

Chapter 15. Functional Programming Languages ISBN Chapter 15 Functional Programming Languages ISBN 0-321-49362-1 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language:

More information

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P - Introduction L I S P

More information

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Scheme in Scheme: The Metacircular Evaluator Eval and Apply Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,

More information

Principles of Programming Languages 2017W, Functional Programming

Principles of Programming Languages 2017W, Functional Programming Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.

More information

A Small Interpreted Language

A Small Interpreted Language A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that

More information

Functional Programming Lecture 1: Introduction

Functional Programming Lecture 1: Introduction Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements

More information

Documentation for LISP in BASIC

Documentation for LISP in BASIC Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have

More information

Chapter 1. Fundamentals of Higher Order Programming

Chapter 1. Fundamentals of Higher Order Programming Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

More information

Common LISP Tutorial 1 (Basic)

Common LISP Tutorial 1 (Basic) Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)

More information

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson Introduction to Functional Programming in Racket CS 550 Programming Languages Jeremy Johnson 1 Objective To introduce functional programming in racket Programs are functions and their semantics involve

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp. Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also

More information

Introduction to Scheme

Introduction to Scheme How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free

More information

More Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list?

More Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list? More Scheme CS 331 Quiz 1. What is (car ((2) 3 4))? (2) 2. What is (cdr ((2) (3) (4)))? ((3)(4)) 3. What is (cons 2 (2 3 4))? (2 2 3 4) 4. What is the length of the list (()()()())? 4 5. Which element

More information

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0)) SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

A Brief Introduction to Scheme (II)

A Brief Introduction to Scheme (II) A Brief Introduction to Scheme (II) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Lists Scheme II p.1/29 Lists Aggregate data

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

Functional Programming

Functional Programming Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming

More information

CSE 341 Section Handout #6 Cheat Sheet

CSE 341 Section Handout #6 Cheat Sheet Cheat Sheet Types numbers: integers (3, 802), reals (3.4), rationals (3/4), complex (2+3.4i) symbols: x, y, hello, r2d2 booleans: #t, #f strings: "hello", "how are you?" lists: (list 3 4 5) (list 98.5

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

Chapter 15. Functional Programming Languages

Chapter 15. Functional Programming Languages Chapter 15 Functional Programming Languages Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: Lisp Introduction

More information

Streams and Evalutation Strategies

Streams and Evalutation Strategies Data and Program Structure Streams and Evalutation Strategies Lecture V Ahmed Rezine Linköpings Universitet TDDA69, VT 2014 Lecture 2: Class descriptions - message passing ( define ( make-account balance

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 3: Scheme Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus. Variables and Functions. cs3723 1 Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

More information

Functional Programming

Functional Programming Functional Programming Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Brief

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 17: Functional Programming Zheng (Eddy Zhang Rutgers University April 4, 2018 Class Information Homework 6 will be posted later today. All test cases

More information

Functional Programming in Scheme

Functional Programming in Scheme Cristian Giumale / Lecture Notes 1 Functional Programming in Scheme Functional programming languages - or applicative languages - follow closely the Lambda calculus model. Their strengths and weaknesses

More information

Introduction to Functional Programming

Introduction to Functional Programming Introduction to Functional Programming Xiao Jia xjia@cs.sjtu.edu.cn Summer 2013 Scheme Appeared in 1975 Designed by Guy L. Steele Gerald Jay Sussman Influenced by Lisp, ALGOL Influenced Common Lisp, Haskell,

More information

Lecture Notes on Lisp A Brief Introduction

Lecture Notes on Lisp A Brief Introduction Why Lisp? Lecture Notes on Lisp A Brief Introduction Because it s the most widely used AI programming language Because Prof Peng likes using it Because it s good for writing production software (Graham

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Week 4: Functional Programming

Week 4: Functional Programming CS320 Principles of Programming Languages Week 4: Functional Programming Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Week 4: Functional Programming 1/ 66 Topic List for this Unit Functional

More information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information