Principles of Programming Languages

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Principles of Programming Languages"

Transcription

1 Principles of Programming Languages Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1

2 What we accomplished so far Different programming languages encourage different programming practices (and make other difficult) o IP (imperative programming) vs. FP (functional programming) o FPs tools include: - first class citizen functions - immutability - functional abstractions 2

3 What we accomplished so far Two aspects in program definition: o The syntactic domain: Expressions - created inductively from atoms using combination operators o The semantic domain: Values - computed inductively when evaluating expressions o Operational semantics: give meaning to expressions by describing the evaluation process 3

4 What we accomplished so far Data types denotes sets of values on which operations can be preformed uniformly o Primitive types o User-defined types Data types can be related to one another using set relations (subsumed-in, disjoint, ) Data types can be created from other data types using set operations (union, intersection, product) 4

5 What we accomplished so far We can use a type-language to associate datatypes to expressions othe type-language is build inductively using the type-system) Some programs allow programmers to annotate variables and functions with type annotations A type checker can establish that a given program satisfies the type declaration constraints. 5

6 Our next mission Learn a small functional programming language with a formal definition of its syntax a formal definition of its operational semantics build an interpreter - a program computing the value of expressions following the inductive definition provided by the operational semantics Semantics: <expr> -> <value> interpreters provide 6 Interpreter: a program implementing the semantics function a clarification mechanism an Illustration mechanism

7 Which language? What properties should a language that is good for learning principles of programming languages have? 7

8 Why Scheme In one word: Minimalistic a small language - a small number of primitives, - a small number of constructs - a small number of data-types common syntax to all composite expressions common semantics to all composite expression Compare to Javascript Yet: it is expressive: Turing complete allows powerful functional abstractions which make programming productive 8

9 Plan Introduce syntactic constructs and their semantics in a gradual manner L0 L1 L2 L3 9 Scheme

10 Specifying a programming language How do we specify a programming language? What are the elements that together define a language? The key elements are: Primitives Primitive literal values (numbers, booleans) Primitive operations (arithmetic ops, comparison ops) Combination means Means to create compound values Means to create compound expressions Abstraction Expressions Means to manipulate compound objects as standalone units Two aspects Values 10

11 L0 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = Compound expressions 4. compound expressions (op expr 1 expr n ) 11

12 L0 - examples 8 (+ 1 7) 42 (- 45 3) 14 (* 2 7) 9 (/ 45 5) #f (> 2 7) 12

13 L0 - examples 16 (* (+ 1 1) (- 9 1)) #t (= (+ 1 5) (- 9 3)) (* (+ 1 1) (- 9 1)) 16 (= (+ 1 5) (- 9 3)) #t Why prefix notation? 10 ( ) 13

14 L0 - examples 4 4 #t #t + #<procedure:+> 14

15 L0 - Semantics Atomic expressions 1. Number literal expression 0, 1, 2, Evaluates to the corresponding numeric value 2. Boolean literal expression #t, #f Evaluates to the corresponding boolean value The atomic expressions evaluate to themselves 3. Primitive operation expression +, -, *, /, <, >, = Evaluates to the corresponding operation <procedure:op> Compound expressions 4. compound expressions (op expr 1 expr n ) 1. Let (val 0,val 1,,val n ) = (evaluate(op), evaluate(exp n ),, evaluate(exp n )) 2. Apply the procedure val 0 to the values val 1,,val n Recursive application 15

16 L0 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = Compound expressions 4. compound expressions (op expr 1 expr n ) What is missing from L0? (+ (- (* 2 37) 18) (* 9 (- (* 2 37) 18)))) abstraction - one of the key components! 16

17 Naming 17 We will add to L0 a means to name expressions. 6 (define size 6) size (* 2 size) 12 (define <name> <expr>) (define area (* size size)) area 36 size in this context is called a variable a variable as in math rather than as in IP The relation between a variable and the value it denotes is called a binding

18 Evaluating the define form (define <var> <expr>) The interpreter maintains a global environment: a table recording the bindings between variables and their values The evaluation rule for (define <var> <expr>) is 1. Let val = Evaluate(<expr>) 2. Add the binding (<var> val) to the global environment 3. Return void (= has no return value) 18 global env. variable value milion pi size 6 global env. : variable => value

19 L1 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = 4. Variable expression size, my-secret-num, Compound expressions 5. special compound expressions (define <var> <expr>) 6. Non-special compound expressions (expr 0 expr 1 expr n ) 19

20 L1 - examples (define size 6) (define pi 3.14) (define area (* (* size size) pi)) area (+ area (* 2 3)) In the evaluation of define the expr is evaluated variable value size 6 pi area

21 L1 - Semantics Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = 4. Variable expression size, secret-num, Compound expressions 5. special compound expressions (define <var> <expr>) Lookup the variable in the env. Return the corresponding value special form 6. Non-special compound expressions (expr 0 expr 1 expr n ) non-special form 21 Evaluate: variable => value Need an evaluation rule for each of our constructs

22 special vs. non-special forms Two types of compound expressions (expr 0 expr 1 expr n ) non-special form all expressions are evaluated (keyword ) special form not all expressions are evaluate first expr is assumed to be a procedure first expr is a keyword 22 the evaluation rule is the fixed the evaluation rule depends on the keyword

23 Evaluation of Non-Special Forms (expr_0 expr_1 expr_2 expr_n) 1. Evaluate all subexpressions expr_i. The value of expr_0 must be of type Procedure, otherwise the evaluation fails (run-time error). 2. Apply the procedure which is the value of expr_0, to the values of the other subexpressions. 23

24 Evaluation of Non-Special Forms (expr_0 expr_1 expr_2 expr_n) The evaluation rule is recursive (* 3 (+ 2 ( ))) 309 (* 3 ( )) (* 3 103) 24

25 L1 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = 4. Variable expression size, my-secret-num, Compound expressions 5. special compound expressions (define <var> <expr>) 6. Non-special compound expressions (expr 0 expr 1 expr n ) 25 What is missing from L1? No conditional expressions No way to define functions (that receive parameters)

26 Defining procedures In Typescript they are called functions, in Scheme procedures. What defines a function? Domain Range Giving it a name or not is a different issue a function associates an element d of the domain to an element r of the range a computable function associates with an element d of the domain some transformation (computation) on d 26

27 Defining procedures Syntax of procedure definition (lambda <parameters> <func-body>) where the syntax for <parameters> is And the syntax for <func-body> is (<param_1> <param_2> <param_n>) <expr_1> <expr_2> <expr_n> 27

28 Defining procedures (lambda <parameters> <func-body>) 28 (lambda (x) (* x x)) (lambda (x y z) (+ x y z)) Such expressions result in a procedure definition Not a procedure application (lambda (x y) (+ (* x x) (* 2 x y) (* y y))) We can think of lambda as the constructor of functions

29 Applying procedures (<proc> <parameters>) ((lambda (x) (* x x)) 3) 9 my-proc ((lambda (x y z) (+ x y z)) 1 2 3) my-proc 6 ((lambda (x y) (+ (* x x) (* 2 x y) (* y y))) 1 2) my-proc 9 In the same way as we apply primitive procedures (+ x y) (proc x y) can be a user-defined procedure 29

30 Note the difference The special lambda form The non-special form (lambda (x) (* x x)) ((lambda (x) (* x x)) 3) #procedure 9 user defined procedure Declaration of an anonymous procedure (same as x => x*x in Typescript) Note the syntactic differences The common way to apply procedure on parameters 30 The result is the value procedure The result is a value

31 Evaluating procedure applications ((lambda (<params>) <expr1> <expr2> <exprn>) <act-params>) The <func-body> can be made of multiple expressions The evaluation rule evaluates all the expressions and returns the value of the last one. What is this useful for? 31

32 What is it useful for? 9 ((lambda (x) (+ x 100) (* x (+ x 329)) (* x x)) 3) ((lambda (x) (display x) (* x x)) 3) 39 Only the last expression affects the returned value Multiple expressions in the body are useful when side-effects are desired ((lambda (x) (display x) (newline) (* x x)) 3) The expression for the returned value should always come last!

33 Naming procedures Every expression in Scheme can be named using the following syntax (define <name> <expr>) (define ten 10) ten 10 (define square (lambda (x) (* x x))) square name expr #<procedure:square> 16 (square 4) 33

34 Naming procedures For naming functions we also have the following (syntactic sugaring) form (define (<name> <parameters>) <body-expr>) (define (square x) (* x x))) (define square square (lambda (x) (* x x))) #<procedure:square> These two forms have exactly the (square 4) same semantics! (define area (* (* size size) pi)) Note the differences with area Had the function referred to a variable which is not local or a parameter, its current value would have been recorded as well! variable value size 6 pi area square #(Closure (x) (* x x)) The closure

35 The if special form (if <predicate> <consequent> <alternative>) (if (< 1 100) "then-part" "else-part") "then-part" (if (< 100 1) "then-part" "else-part") "else-part" (if (< 1 100) (+ 2 2) (* 7 7)) 4 (if (< 100 1) (+ 2 2) (* 7 7)) 35 49

36 The if special form Is the alternative (else-part) evaluated when the condition is (evaluated to) true? (if (< 1 100) (/ 1 0) (* 7 7)) /: division by zero (if (< 1 100) (+ 2 2) (/ 1 0)) 4 36

37 Evaluating the if special form (if <predicate> <consequent> <alternative>) Let p = Evaluate (<predicate>) If p is #t, Evaluate(<consequent>) and return it Otherwise Evaluate(<alternative>) and return it 37 In the if special form one of the expressions is not evaluated Unlike the non-special form in which all expressions are evaluated

38 The cond special form -Examples (cond ((> 1 2) first" ) ((> 2 2) "second") ((> 3 2) third" )) "third" (cond ((> 1 2) first" ) ((> 2 2) "second") (else third" )) "third" (cond ((> 1 2) "first" "FIRST") ((> 2 2) "second" "SECOND") ((> 3 2) "third" "THIRD")) "THIRD" (cond ((> 1 2) (display "first") "FIRST") ((> 2 2) (display "second") "SECOND") ((> 3 2) (display "third") "THIRD")) 38 third"third"

39 The cold special form (cond (<pred 1 > <expr-1 1 > <expr-2 1 > <expr-n 1 >) (<pred 2 > <expr-1 2 > <expr-2 2 > <expr-k 2 >) (<pred n > <expr-1 n > <expr-2 n > <expr-m n >) (else <expr-1 e > <expr-2 e > <expr-l e >)) A syntactic sugaring of if Thus, the only expressions that are evaluated are those corresponding to the first predicate to evaluate to true Only the predicates until the first predicate to evaluate to true are evaluated 39

40 L2 - Example Implementing Newton's method for computing square roots Newton's method is stated as this algorithm: If g is non-zero guess for a square root of x, then (g + x/g) / 2 is a better approximation of x. This algorithm is iterative! Interestingly, we can implement it although we have no construct for iteration 40

41 L2 - Example Auxiliary functions 41

42 L2 - Example As long as the guess is not good enough, improve it improved guess 42 First guess is set to 1 Check the difference between guess*guess and x is small enough Improve the guess according to Newton s method

43 L2 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = 4. Variable expression size, my-secret-num, Compound expressions 5. special compound expressions I. (define <var> <expr>) II. (lambda <parameters> <func-body>) III. (if <predicate> <consequent> <alternative>) IV. (cond ) 6. Non-special compound expressions (expr 0 expr 1 expr n ) 43

44 L2 - Semantics not all expressions are evaluated Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, = 4. Variable expression size, my-secret-num, Compound expressions 5. special compound expressions I. (define <var> <expr>) II. (lambda <parameters> <func-body>) III. (if <predicate> <consequent> <alternative>) IV. (cond ) all are 6. Non-special compound expressions (expr 0 expr 1 expr n ) 44

45 Review of Last Lecture L3 L2 L1 if define cond only primitive ops and types lambda recursive comb. of primitive ops. supports recursive procedures Scheme 45

46 What is missing from L2? Compound values! In Javascript we have: array [] map {} What are the minimal constructs that we need to add in order to obtain array and map capabilities? 46

47 The pair compound data type The pair compound data type combines two values into a single unit. To support this the language provides: A value constructor (called cons) Accessors to take apart a compound pair value: for the first (called car) for the second (called cdr) A type predicate to check whether a value belongs to the set of pair values (called pair?) An equality predicate for pairs (called equal?) 47 To support pairs we add 5 primitive functions: cons, car, cdr, pair?, equal?

48 Pair, and associated types Types of the pair constructor and accessors: cons: [T 1 *T 2 -> Pair(T 1,T 2 )] car: [Pair(T 1,T 2 ) -> T 1 ] cdr: [Pair(T 1,T 2 ) -> T 2 ] pair?: [Any -> boolean] equal?: [Any * Any -> boolean] 48

49 L3 - pair examples (define foo (cons 1 2)) (car foo) 1 (cdr foo) 2 (define bar (cons 1 2)) (equal? foo bar) #t (pair? foo) #t 49 (pair? 2) #f

50 L3 - nesting pairs (define p12 (cons 1 2)) (define p123 (cons p12 3)) (define p1234 (cons p123 4)) (define p12345 (cons p1234 5)) p12345 '((((1. 2). 3). 4). 5) (car p12345) '(((1. 2). 3). 4) 3 (cdr (car (car p12345))) (cdr p12345) 5 Syntactic sugaring 3 (cdaar p12345))) 50 Can we use this to implement lists? What about the empty list???

51 Lists Using literals A list is an inductive data type. The base case is the empty list The inductive case creates a non-empty list by combining an element with a list (define L1234 '( ))) L1234 E1234 '( ) '( ) Using the list constructor (define E1234 (list ))) 51 (define Lemp '()) Lemp '() (define Eemp (list)) Eemp '() (define C1234 (cons 1 (cons 2 (cons 3 (cons 4 ())))))) C1234 '( ) Using the pair constructor

52 Lists Lists can indeed be implemented using pairs and the empty list (and in fact are implemented this way in scheme) But the language also offers special constructs to deal with lists: A list constructor : (list <el1> <eln>) A literal list : (<el1> <eln>) Accessors first, second, third, A type predicate to check whether a value belongs to the set of list values (called list?) An emptiness predicate for list (called empty?) 52

53 functions on list : length (define length (lambda (l) (if (empty? l) 0 (+ 1 (length (cdr l)))))) Recursive functions operating on inductive data types follow their inductive definition 53

54 functions on list : n-th (define nth (lambda (n l) (cond [(empty? l) '()] [(= n 0) (car l)] [else (nth (- n 1) (cdr l))]))) 54 (nth 2 '( )) 3 What happened here? (nth 8 '( )) '() (nth 0 '( )) 1

55 functions on list : n-th (define nth (lambda (n l) (cond [(empty? l) '()] [(= n 0) (car l)] [else (display (list "n:" n " l:" l)) (newline) (nth (- n 1) (cdr l))]))) Recall: the debug printing must precede the last expression, which is the returned value (nth 8 '( )) 55 (n: 8 l: ( )) (n: 7 l: (2 3 4)) (n: 6 l: (3 4)) (n: 5 l: (4)) '()

56 L3 - Syntax Atomic expressions 1. Number literal expression 0, 1, 2, 2. Boolean literal expression #t, #f 3. Primitive operation expression +, -, *, /, <, >, =, cons, car, cdr, pair?, list?, empty? 4. Variable expression size, my-secret-num, 5. The empty list literal expression `() Compound expressions 6. special compound expressions I. (define <var> <expr>) II. (lambda <parameters> <func-body>) III. (if <predicate> <consequent> <alternative>) IV. (cond ) 7. Non-special compound expressions (expr 0 expr 1 expr n ) 56

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Collaboration and Management Dana Fisman Lesson 2 - Types with TypeScript 1 Types What are types in programming languages? What types are you

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

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

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

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) What is the Metacircular Evaluator? It is the best part

More information

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the

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

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 4 - Type Checking Collaboration and Management Dana Fisman 1 Why declare types? Declaring types allows the compiler to detect errors

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

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

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

Denotational Semantics. Domain Theory

Denotational Semantics. Domain Theory Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning

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

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

Project 2: Scheme Interpreter

Project 2: Scheme Interpreter Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

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

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

Scheme as implemented by Racket

Scheme as implemented by Racket Scheme as implemented by Racket (Simple view:) Racket is a version of Scheme. (Full view:) Racket is a platform for implementing and using many languages, and Scheme is one of those that come out of the

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Building a system for symbolic differentiation

Building a system for symbolic differentiation Computer Science 21b Structure and Interpretation of Computer Programs Building a system for symbolic differentiation Selectors, constructors and predicates: (constant? e) Is e a constant? (variable? e)

More information

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example. Racket Next 2+ weeks will use the Racket language (not ML) and the DrRacket programming environment (not emacs) Installation / basic usage instructions on course website CSE34: Programming Languages Lecture

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

Scheme Basics > (butfirst '(help!)) ()

Scheme Basics > (butfirst '(help!)) () Scheme Basics > (butfirst '(help!)) () [The butfirst of a *sentence* containing one word is all but that word, i.e., the empty sentence. (BUTFIRST 'HELP!) without the inner parentheses would be butfirst

More information

Scheme: Strings Scheme: I/O

Scheme: Strings Scheme: I/O Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of

More information

Common LISP-Introduction

Common LISP-Introduction Common LISP-Introduction 1. The primary data structure in LISP is called the s-expression (symbolic expression). There are two basic types of s-expressions: atoms and lists. 2. The LISP language is normally

More information

6.821 Programming Languages Handout Fall MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science

6.821 Programming Languages Handout Fall MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science 6.821 Programming Languages Handout Fall 2002 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science Problem Set 6 Problem 1: cellof Subtyping Do exercise 11.6

More information

Functional Programming - 2. Higher Order Functions

Functional Programming - 2. Higher Order Functions Functional Programming - 2 Higher Order Functions Map on a list Apply Reductions: foldr, foldl Lexical scoping with let s Functional-11, CS5314, Sp16 BGRyder 1 Higher Order Functions Functions as 1st class

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

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

Racket: Modules, Contracts, Languages

Racket: Modules, Contracts, Languages Racket: Modules, Contracts, Languages Advanced Functional Programming Jean-Noël Monette November 2013 1 Today Modules are the way to structure larger programs in smaller pieces. Modules can import and

More information

MetacircularScheme! (a variant of lisp)

MetacircularScheme! (a variant of lisp) MetacircularScheme! (a variant of lisp) Lisp = Beauty Passed on through ages Basic Expressions (function arg1 arg2 ) To evaluate an expression, apply the functionto the arguments. (+ 1 2)? => 3 (sqrt4)?

More information

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation?

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation? Normal Order (Lazy) Evaluation Alternative models for computation: Normal (Lazy) Order Evaluation Memoization Streams Applicative Order: evaluate all arguments, then apply operator Normal Order: pass unevaluated

More information

;;; Determines if e is a primitive by looking it up in the primitive environment. ;;; Define indentation and output routines for the output for

;;; Determines if e is a primitive by looking it up in the primitive environment. ;;; Define indentation and output routines for the output for Page 1/11 (require (lib "trace")) Allow tracing to be turned on and off (define tracing #f) Define a string to hold the error messages created during syntax checking (define error msg ""); Used for fancy

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

WELCOME! (download slides and.py files and follow along!) LECTURE 1

WELCOME! (download slides and.py files and follow along!) LECTURE 1 WELCOME! (download slides and.py files and follow along!) 6.0001 LECTURE 1 6.0001 LECTURE 1 1 TODAY course info what is computation python basics mathematical operations python variables and types NOTE:

More information

Problem Set 4: Streams and Lazy Evaluation

Problem Set 4: Streams and Lazy Evaluation Due Friday, March 24 Computer Science (1)21b (Spring Term, 2017) Structure and Interpretation of Computer Programs Problem Set 4: Streams and Lazy Evaluation Reading Assignment: Chapter 3, Section 3.5.

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

CS 480. Lisp J. Kosecka George Mason University. Lisp Slides

CS 480. Lisp J. Kosecka George Mason University. Lisp Slides CS 480 Lisp J. Kosecka George Mason University Lisp Slides Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic

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

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

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

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

Introduction to Functional Programming in Haskell 1 / 56

Introduction to Functional Programming in Haskell 1 / 56 Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order

More information

Parser Tools: lex and yacc-style Parsing

Parser Tools: lex and yacc-style Parsing Parser Tools: lex and yacc-style Parsing Version 6.11.0.6 Scott Owens January 6, 2018 This documentation assumes familiarity with lex and yacc style lexer and parser generators. 1 Contents 1 Lexers 3 1.1

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

B The SLLGEN Parsing System

B The SLLGEN Parsing System B The SLLGEN Parsing System Programs are just strings of characters. In order to process a program, we need to group these characters into meaningful units. This grouping is usually divided into two stages:

More information

regsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13

regsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13 1 File: regsim.scm Register machine simulator from section 5.2 of STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS This file can be loaded into Scheme as a whole. Then you can define and simulate machines

More information

Programming with Math and Logic

Programming with Math and Logic .. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing

More information

Racket: Macros. Advanced Functional Programming. Jean-Noël Monette. November 2013

Racket: Macros. Advanced Functional Programming. Jean-Noël Monette. November 2013 Racket: Macros Advanced Functional Programming Jean-Noël Monette November 2013 1 Today Macros pattern-based macros Hygiene Syntax objects and general macros Examples 2 Macros (According to the Racket Guide...)

More information

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

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

More information

Lecture 12: Conditional Expressions and Local Binding

Lecture 12: Conditional Expressions and Local Binding Lecture 12: Conditional Expressions and Local Binding Introduction Corresponds to EOPL 3.3-3.4 Please review Version-1 interpreter to make sure that you understand how it works Now we will extend the basic

More information

MIDTERM EXAMINATION - CS130 - Spring 2005

MIDTERM EXAMINATION - CS130 - Spring 2005 MIDTERM EAMINATION - CS130 - Spring 2005 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 231 + 25 extra credit This exam counts for 25%

More information

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs?

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs? Part II. Hoare Logic and Program Verification Part II. Hoare Logic and Program Verification Dilian Gurov Props: Models: Specs: Method: Tool: safety of data manipulation source code logic assertions Hoare

More information

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89 Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the

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

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

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,

More information

Verification of an ML compiler. Lecture 3: Closures, closure conversion and call optimisations

Verification of an ML compiler. Lecture 3: Closures, closure conversion and call optimisations Verification of an ML compiler Lecture 3: Closures, closure conversion and call optimisations Marktoberdorf Summer School MOD 2017 Magnus O. Myreen, Chalmers University of Technology Implementing the ML

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

Name EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) )

Name EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) ) CS 345 Spring 2010 Midterm Exam Name EID 1. [4 Points] Circle the binding instances in the following expression: (calc (parse '+ with x + 5 5 with y - x 3 + y y z ) ) 2. [7 Points] Using the following

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

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

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

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

More information

# true;; - : bool = true. # false;; - : bool = false 9/10/ // = {s (5, "hi", 3.2), c 4, a 1, b 5} 9/10/2017 4

# true;; - : bool = true. # false;; - : bool = false 9/10/ // = {s (5, hi, 3.2), c 4, a 1, b 5} 9/10/2017 4 Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Sasa Misailovic 4110 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421a # true;; - : bool = true # false;; - : bool

More information

7. Introduction to Denotational Semantics. Oscar Nierstrasz

7. Introduction to Denotational Semantics. Oscar Nierstrasz 7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,

More information

CS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College

CS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College CS5 Programming Languages Handout # 9 Prof. Lyn Turbak March, 00 Wellesley College Postfix: A Simple Stack Language Several exercises and examples in this course will involve the Postfix mini-language.

More information

COAL (COmplex Arithmetic Language) Reference Manual

COAL (COmplex Arithmetic Language) Reference Manual COAL (COmplex Arithmetic Language) Reference Manual March 09, 2009 COMS W4115 Eliot Scull (CVN) e.scull@computer.org 1 Introduction This manual describes the COAL language (COmplex Arithmetic Language)

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Essentials of Programming Languages Language

Essentials of Programming Languages Language Essentials of Programming Languages Language Version 6.90.0.26 April 20, 2018 The Essentials of Programming Languages language in DrRacket provides a subset of functions and syntactic forms of racket mostly

More information

ASML Language Reference Manual

ASML Language Reference Manual ASML Language Reference Manual Tim Favorite (tuf1) & Frank Smith (fas2114) - Team SoundHammer Columbia University COMS W4115 - Programming Languages & Translators 1. Introduction The purpose of Atomic

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4 CS321 Languages and Compiler Design I Winter 2012 Lecture 4 1 LEXICAL ANALYSIS Convert source file characters into token stream. Remove content-free characters (comments, whitespace,...) Detect lexical

More information

Implementing Continuations

Implementing Continuations Implementing Continuations sk and dbtucker 2002-10-18 1 Changing Representations Now that we ve seen how continuations work, let s study how to implement them in an interpreter. For this lecture onward,

More information

How to Design Programs Languages

How to Design Programs Languages How to Design Programs Languages Version 4.1 August 12, 2008 The languages documented in this manual are provided by DrScheme to be used with the How to Design Programs book. 1 Contents 1 Beginning Student

More information

Values and Variables 1 / 30

Values and Variables 1 / 30 Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

More information

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler. Name: Midterm Exam PID: This is a closed-book exam; you may not use any tools besides a pen. You have 75 minutes to answer all questions. There are a total of 75 points available. Please write legibly;

More information

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4 CS 61A Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that

More information

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens Syntactic Analysis CS45H: Programming Languages Lecture : Lexical Analysis Thomas Dillig Main Question: How to give structure to strings Analogy: Understanding an English sentence First, we separate a

More information

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3)

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3) Declarative Computation Model Single assignment store (VRH 2.2) Kernel language syntax (VRH 2.3) Carlos Varela RPI October 6, 2009 Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL On Academic

More information

Thoughts on Assignment 4 Haskell: Flow of Control

Thoughts on Assignment 4 Haskell: Flow of Control Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer

More information

19 Machine Learning in Lisp

19 Machine Learning in Lisp 19 Machine Learning in Lisp Chapter Objectives Chapter Contents ID3 algorithm and inducing decision trees from lists of examples. A basic Lisp implementation of ID3 Demonstration on a simple credit assessment

More information

Vectors in Scheme. Data Structures in Scheme

Vectors in Scheme. Data Structures in Scheme Data Structures in Scheme Vectors in Scheme In Scheme, lists and S-expressions are basic. Arrays can be simulated using lists, but access to elements deep in the list can be slow (since a list is a linked

More information

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF) Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical

More information

CIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires

CIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires 1 A couple of Functions 1 Let's take another example of a simple lisp function { one that does insertion sort. Let us assume that this sort function takes as input a list of numbers and sorts them in ascending

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

Warm-up and Memoization

Warm-up and Memoization CSE341 Spring 05 Due Wednesday, May 11 Assignment 4 Part I Warm-up and Memoization Warm-up As a warm-up, write the following Scheme functions: 1. Write the function foldl of the form (foldl func initial

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples: COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea:

More information

Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Booleans and Short-Circuit Evaluation. Tuples as Values.

Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Booleans and Short-Circuit Evaluation. Tuples as Values. Booleans (aka Truth Values) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421d # true;; - : bool = true # false;; - : bool =

More information

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal

More information

Resources matter. Orders of Growth of Processes. R(n)= (n 2 ) Orders of growth of processes. Partial trace for (ifact 4) Partial trace for (fact 4)

Resources matter. Orders of Growth of Processes. R(n)= (n 2 ) Orders of growth of processes. Partial trace for (ifact 4) Partial trace for (fact 4) Orders of Growth of Processes Today s topics Resources used by a program to solve a problem of size n Time Space Define order of growth Visualizing resources utilization using our model of evaluation Relating

More information

Programming Languages. Function-Closure Idioms. Adapted from Dan Grossman's PL class, U. of Washington

Programming Languages. Function-Closure Idioms. Adapted from Dan Grossman's PL class, U. of Washington Programming Languages Function-Closure Idioms Adapted from Dan Grossman's PL class, U. of Washington More idioms We know the rule for lexical scope and function closures Now what is it good for A partial

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

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far. Lecture Outline Operational Semantics of Cool COOL operational semantics Motivation Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Notation The rules CS781(Prasad) L24CG 1 CS781(Prasad)

More information

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page. MORE SCHEME COMPUTER SCIENCE MENTORS 61A October 30 to November 3, 2017 1 What Would Scheme Print? Solutions begin on the following page. 1. What will Scheme output? Draw box-and-pointer diagrams to help

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

Syntax: Meta-Programming Helpers

Syntax: Meta-Programming Helpers Syntax: Meta-Programming Helpers Version 5.0.1 August 3, 2010 1 Contents 1 Syntax Object Helpers 5 1.1 Deconstructing Syntax Objects........................ 5 1.2 Matching Fully-Expanded Expressions....................

More information

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without previous written authorization. 1 2 The simplest way to create

More information