6.001 Final Exam Review Spring 2005 By Gerald Dalley.

Slides:



Advertisements
Similar presentations
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
Advertisements

1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
1 The metacircular evaluator Names Extend the calculator to store intermediate results as named values (define x (+ 4 5)) store result as x (+ x.
Metacircular Evaluation SICP Chapter 4 Mark Boady.
1 The Metacircular Evaluator Chapter 4 Section 4.1 We will not cover every little detail in the lectures, so you MUST read Section 4.1 in full.
מבוא מורחב - שיעור 15 1 Lecture 15 Streams. מבוא מורחב - שיעור 15 2 Streams: Motivation (define (sum-primes a b) (define (iter count accum) (cond ((>
1 Lecture 18 Continue Evaluator. 2 z9 true#t + twice Representing procedures (eval '(define twice (lambda (x) (+ x x))) GE) symbol primitive scheme procedure.
6.001 SICP 1 Normal (Lazy) Order Evaluation Memoization Streams.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Extended Introduction to CS Preparation for Final Exam.
Types of the past exam questions I. Write/Complete Code II. Evaluate Expressions III. Analyze Complexity IV. Meta-circular Evaluator.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 11. Dotted tail notation (define (proc m1 m2. opt) ) Mandatory Arguments: m1, m2 Mandatory Arguments: m1, m2.
6.001 SICP SICP – September ? 6001-Introduction Trevor Darrell 32-D web page: section.
Extended Introduction to CS Preparation for Final Exam.
Picking and Choosing… …Amb Above the Line. Intro to Nondeterminism So before we programmed to compute an answer to a problem. What if we set up a system.
SICP Data Mutation Primitive and Compound Data Mutators Stack Example non-mutating mutating Queue Example non-mutating mutating.
SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic.
1 Functional languages (e.g. Scheme, ML) Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
1 Lecture 15: More about assignment and the Environment Model (EM)
1 Saves repeated renaming and substitution: explicit substitution is replaced by variable bindings using new data structures (frame, environment). Can.
1 Lecture OO, the notion of inheritance 3 Stacks in OO style (define (make-stack) (let ((top-ptr '())) (define (empty?) (null? top-ptr)) (define.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is aa good way to learn more about programming languages  Interpreters are.
1 The metacircular evaluator (Cont.) Defining new procedures (define (lambda? e) (tag-check e 'lambda)) (define (eval exp env) (cond ((number? exp)
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
1/21 4/6/2004 OOPS – One more example Goal: See an example that distinguishes between –“is-a” or inheritance relationships –“has-a” or local variable relationships.
SICP Interpretation Parts of an interpreter Arithmetic calculator Names Conditionals and if Storing procedures in the environment Environment as.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
1 Read-Eval-Print Loop (define (driver-loop) (prompt-for-input input-prompt) (let ((input (read))) (let ((output (eval input the-global-env))) (announce-output.
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 14: Object Oriented Programming 한 태숙.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
1 Programming Languages (CS 550) Lecture 4 Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
1 Env. Model Implementation & Analyzer Practice Session #10 Env. Model Implementation & Analyzer Practice Session #10.
1 Lecture 19 Dynamic Scoping Lazy Evaluation (4.2.1, 4.2.2)
1 מבוא מורחב למדעי המחשב בשפת Scheme תרגול Outline Mutable list structure RPN calculator Vectors and sorting.
6.037 Lecture 7B Scheme Variants Normal Order Lazy Evaluation Streams Edited by Mike Phillips & Ben Vandiver Original Material by Eric Grimson & Duane.
CSE 341 Lecture 21 delayed evaluation; thunks; streams slides created by Marty Stepp
CS314 – Section 5 Recitation 9
Operational Semantics of Scheme
Edited by Original material by Eric Grimson
6.001 Jeopardy.
6.001 SICP Variations on a Scheme
The interpreter.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Lecture 14 - Environment Model (cont.) - Mutation - Stacks and Queues
Env. Model Implementation
Original material by Eric Grimson
The Metacircular Evaluator
Lecture 18 Infinite Streams and
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
The Metacircular Evaluator (Continued)
Lecture 26: The Metacircular Evaluator Eval Apply
6.001 SICP Further Variations on a Scheme
Explicit Application of Procedures, and Explicit Evaluation
Streams, Delayed Evaluation and a Normal Order Interpreter
Lecture 14 - Environment Model (cont.) - Mutation - Stacks and Queues
6.001 SICP Variations on a Scheme
Lecture 14: The environment model (cont
Announcements Quiz 5 HW6 due October 23
List and list operations (continue).
6.001 SICP Interpretation Parts of an interpreter
topics interpreters meta-linguistic abstraction eval and apply
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
More Scheme CS 331.
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

6.001 Final Exam Review Spring 2005 By Gerald Dalley

Study Resources Lectures – lecture had some good summary portions (+ preview of future courses) Previous exams –Skip any problems with ec-eval or (goto …) Online tutor Tutorial problems

Topics Scheme Procedures and recursion Orders of growth Data abstractions Higher-order procedures Program methodology Symbols and quotation Abstract data types Mutation Environment model Object-oriented systems Interpretation / evaluation Lazy evaluation Asynchronous computing

Fall 1998 Exam: True/False If the Scheme evaluator supports the delay and force special forms, it is possible for the Scheme user to implement cond as a simple procedure without additional extensions to the evaluator. –False: delay requires that the user explicitly mark delayed expressions. The cond “procedure” needs to implicitly delay all of its arguments. Deadlock can occur between two processes that are running in parallel if a mutual exclusion approach is used (such as the synchronization approach discussed in class) in which both processes try to gain access to a single shared resource. –False: we need two shared resources for deadlock (given the scheme presented in class)

Box-and-Pointers (define mob '( )) (set-cdr! (cdddr mob) mob) (define (l x y) (set-car! x y) (set-car! y x)) (l mob (cddr mob)) (l (cdr mob) (cdddr mob)) mob

Box-and-Pointers (define mob '( )) (set-cdr! (cdddr mob) mob) (define (l x y) (set-car! x y) (set-car! y x)) (l mob (cddr mob)) (l (cdr mob) (cdddr mob)) mob 1324

Listless Fun What is the final value of z? (define x '(1 2 3)) (define y '(4 5 6)) (define z (list (list (list x y)) x 7)) (set-cdr! (cddr x) (third z)) (((( ) (4 5 6))) ( ) 7)

Orders of Growth (define (find-e n) (if (= n 0) 1. (+ (/ (fact n)) (find-e (- n 1))))) Time: Θ(n 2 ) Space: Θ(n) (define (fast-expt x n) (cond ((= n 0) 1) ((even? n) (fast-expt (* x x) (/ n 2))) (else (* x (fast-expt x (- n 1)))))) Time: Θ(log n) Space: Θ(log n)

Environmental Trivia To drop a frame… (let ((…) …) …) (proc …) To create a double-bubble… (let ((…) …) …) if desugaring (lambda (…) …) (define (foo …) …) Environments form what type of a graph (e.g. chain, tree, directed acyclic graph, general graph, …)? –Tree (Re)memorize the environment model!

ab c Write the Scheme Code to Create the Following Environment Diagram GE

Write the Scheme Code to Create the Following Environment Diagram ab c (load "env-dia.scm") (define c (let ((a (let ((b nil)) (lambda (newb) (set! b newb) b)))) (a (lambda (x) (* x x))))) (env-dia 'render "tricky") GE

OOPs In the following code, how many references are created to the “anakin” symbol? (define (walker self name speed) (let ((named-part (named-object self name))) …)) (define (biker self name speed) (let ((named-part (named-object self name))) …)) (define (swimmer self name speed) (let ((named-part (named-object self name))) …)) (define (tri-athlete self name walk-speed bike-speed swim-speed) (let ((walker-part (walker self name walk-speed)) (biker-part (biker self name bike-speed)) (swimmer-part (swimmer self name swim-speed))) …)) (define (jedi self name) (let ((tri-athlete-part (tri-athelete self name ))) …)) (define anakin (create-jedi 'anakin)) 8 (3 named-objects, walker, biker, swimmer, tri-athlete, jedi) –Moral: multiple personalities lead to Sithdom.

Meandering Streams (define ones (cons-stream 1 ones)) (define ints (cons-stream 1 (add-streams ones ints))) (define (row rnum col-stream) (if (null? col-stream) '() (cons-stream (list rnum (stream-car col-stream)) (row rnum (stream-cdr col-stream))))) (define (block started-rows next-row col-stream) (define (helper sr) (if (null? sr) (block (append (map stream-cdr started-rows) (list (row (stream-car next-row) col-stream))) (stream-cdr next-row) col-stream) (cons-stream (stream-car (car sr)) (helper (cdr sr))))) (helper (reverse started-rows))) (show-stream (block nil ints ints) 15) 1234… 1(1 1)(1 2)(1 3)(1 4)… 2(2 1)(2 2)(2 3)(2 4)… 3(3 1)(3 2)(3 3)(3 4)… 4(4 1)(4 2)(4 3)(4 4)… ……………… What gets displayed by show-stream? (1 1) (2 1) (1 2) (3 1) (2 2) (1 3) (4 1) (3 2) (2 3) (1 4) (5 1) (4 2) (3 3) (2 4) (1 5)

What are the possible values for z at the completion of the parallel-execution below? (define z 5) (define (P1) (set! z (+ z 10))) (define (P2) (set! z (* z 2))) (parallel-execute P1 P2) Fall 1998 Exam: Interleavings

(+ z 10)) (set! z (* z 2)) (set! z  30 (+ z 10)) (* z 2)) (set! z  10 (+ z 10)) (* z 2)) (set! z  15 (* z 2)) (+ z 10)) (set! z  10 (* z 2)) (+ z 10)) (set! z  15 (* z 2)) (set! z (+ z 10)) (set! z  20

foreach special form (foreach var exp body-exp body-exp) (foreach x (list ) (display x) (display " ")) (define foreach-variable second) (define foreach-list third) (define foreach-body cdddr) (define (desugar-foreach exp) `(let loop ((lst,(foreach-list exp))) (if (null? lst) #f (let ((,(foreach-variable exp) (car exp) (loop (cdr lst))))))

foreach special form (foreach var exp body-exp body-exp) (foreach x (list ) (display x) (display " ")) (define foreach-variable second) (define foreach-list third) (define foreach-body cdddr) (define (eval-foreach exp env) (let loop ((lst (foreach-list exp))) (if (null? lst) #f (begin (m-eval `(let ((,(foreach-variable exp),(car exp)) env) (loop (cdr lst))))))

foreach special form (foreach var exp body-exp body-exp) (foreach x (list ) (display x) (display " ")) (define foreach-variable second) (define foreach-list third) (define foreach-body cdddr) (define (eval-foreach-nocapture exp env) (for-each (m-eval `(lambda (,(foreach-variable exp)) env) (m-eval (foreach-list exp) env)))

Cause Light Wounds I call upon chaos to cause unbalanced parentheses. Darkness I summon the darkness of night to hide all free machines. Cause Wounds I call upon the forces of chaos to crash your server. Call Undead I call all environment pointers to this very spot. Cause Disease I call upon the powers of chaos to mutate your pointers. Lie I call upon chaos to make your debugger lie. Cause Serious Wounds I call upon the powers of chaos to cause recursive bugs. Control Undead By death’s dark mantle and the powers of chaos, I control environment pointers to do my bid. Unbind By the powers of chaos, I unbind all variables. Poison I call upon chaos, decay, and rot to panic your process. Cause Critical Wounds I call upon chaos itself to cause fatal errors. Create Undead By the powers of chaos, I create environment pointers. Wither I call upon the powers of darkness to wither your abstractions. Curse I curse your code to forever underflow the stack. Obfuscate I call upon chaos to obfuscate your abstractions. Waste By the powers of darkness, I command you to waste your time optimizing useless abstractions. Quest By the powers of chaos, I quest you on this problem set. Death I grant you the gift of repeating