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

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

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

Transcription

1 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 error messages (define type ""); (define set error message (lambda (message) (set! error msg message))) Environment related function (define make new environment (lambda (bindings old env) (cons bindings old env))) (define lookup in environment (lambda (name env trace?) (if (eq? env null) #f (if trace? (output (format "Looking for ~a in ~a" name (pretty environment env)) # t #t)) (let ((pair (assv name (car env)))) pair (lookup in environment name (cdr env) trace?))))))) (define set in environment (lambda (name env value trace?) (if (eq? env null) #f (if trace? (output (format "Looking for ~a in ~a" name (pretty environment env)) # t #t)) (let ((pair (assv name (car env)))) (set cdr! pair value) (output (format "Setting ~a to ~a!" name value) #t #t) #t) (set in environment name (cdr env) value trace?))))))) (define pretty environment (lambda (env) (list (map (lambda (n v) (list n := v)) (map car (car env)) (map (lambda (x) (if (list? x) (list λ (cadr x)...) x)) (map cdr (car env)))) > parent))) Define a list of primitives (define prim (cons (list (cons + +) (cons ) (cons / /) (cons * *) (cons = =) (cons > >) (cons < <)) null)) is primitive? Determines if e is a primitive by looking it up in the primitive environment prim (define is primitive? (lambda (e) (assv e (car prim)))) Define the global environment (define global env (cons () prim)) Define indentation and output routines for the output for the evaluator (define set error msg (lambda (msg) (set! error msg msg) #f)) (define indent 0) (define output (lambda (str indent? newline?) (if tracing (if indent? (do indent)) (display str) (if newline? ))))) (define do indent (lambda () (letrec ((myindent (lambda (n) (if (> n 0) (display " ") (myindent ( n 2))))))) (myindent indent)))) =============================== ===== RULE IMPLEMENTATION ===== =============================== Page 2/11 Initialization Rule (init rule) Clears the global environment. If you want the global environment to hold an y values at start up you can places them here ; ) old init rule (define init rule (lambda () (set! env (list (cons fact (lambda (n) (if (= n 0) 1 (* n (fact ( n 1))))))))))) new init rule An environment is a pair (e,n), e is the environment bindings, and n is the parent environment. 1/6

2 Page 3/11 the global environment does not have a parent environment. (define init rule (lambda () (set! global env (cons () prim)))) Lambda Rule (lambda rule) As discussed a lambda form has an IMPLICIT begin in its body, so why not just put an EXPLICIT one in there and let the Begin Rule take care of business. Ex. (lambda (x) x) => (lambda (x) x)) ==========> old Lambda Rule (define lambda rule (lambda (lambda form) (let ((l (list lambda (cadr lambda form) (cons begin (cddr lambda form) )))) (output (format "=> ~a [Lambda Rule]" l) #t #t) l))) ==========> new Lambda Rule A lambda (function abstraction) must now carry with it an environment; the e nvironment belonging to a lambda form is the environment which were the present one w hen the lambda rule was called. The lambda rule must thus take in an environment as well. We will represent a lambda as a pair (l,e), where l is the actual lambda for m, and e is the associated environment, i.e., the environment to which the static l ink of any frame evaluating this lambda form must point. (define lambda rule (lambda (lambda form env) (let ((l (list lambda (cadr lambda form) (cons begin (cddr lambda form)) e nv))) (output (format "=> ~a [Lambda Rule]" (list λ (cadr l) (caddr l))) #t #t) l))) Number Rule (number rule) This rule is obsolete; it is being replaced by the Literal Rule; this allows us to use strings and boolean literals too. Though we do not have a way to comp are anything by numbers unless we implement string equal?, and and or. (define number rule (lambda (number) (output (format "=> ~a [Number Rule]" number) #f #t) number))) Literal Rule (literal rule) See the description for the Number Rule (define literal rule (lambda (literal) (output (format "=> ~a [Literal Rule]" literal) #f #t) literal))) Name Rule (name rule) Accepts a name and returns the value from the environment. Page 4/11 ==========> old Name Rule (define name rule (lambda (name) (let ((pair (assv name env))) (output (format "=> ~a [Name Rule]" (cdr pair)) #f #t) (cdr pair)) (let ((pair (assv name prim))) (output (format "=> ~a [Name Rule]" (cdr pair)) #f #t) (cdr pair)) (display (format "reference to undefined identifier: ~a" na me)) (loop)))))))) ==========> new Name Rule A call to the name rule must now include an environment, and instead of doin g an assv call on the global environment, we use lookup in environment to look through the cha in of environments. (define name rule (lambda (name env) (if tracing ) (let ((pair (lookup in environment name env #t))) (output (format "=> ~a [Name Rule]" (if (and (list? (cdr pair)) (eq? l ambda (cadr pair))) (list λ (caddr pair) (cadd dr pair)) (cdr pair))) #t #t) (cdr pair)) (display (format "reference to undefined identifier: ~a" name)) (loop)))))) Primitive Rule (primitive rule) Accepts a primitive and a list of arguments, and applies the primitive to the list of arguments using apply. Note, and and or (which we have not implemented cannot be primitives as Scheme does not allow the use of and and or with apply ; ( (define primitive rule (lambda (primitive arguments) (let ((result (apply primitive arguments))) (output (format "=> ~a [Primitive Rule]" result) #t #t) result))) 2/6

3 Page 5/11 Application Rule (application rule) Evaluates the arguments and calls either the primitive rule or the procedure rule. We do not need an environment here as the lambda form carries with it its own environment. ========> old Application Rule (define application rule (lambda (lst) (let ((primitive? (is primitive? (car lst))) (evaluated args (map evaluate lst))) (if primitive? (primitive rule (car evaluated args) (cdr evaluated args)) (procedure rule (car evaluated args) (cdr evaluated args)))))) ==========> new Application Rule We have recursive calls to evaluate here, so we need to bring along the envi ronment (define application rule (lambda (lst env) (let ((primitive? (is primitive? (car lst))) (evaluated args (map (evaluate form env)) lst))) (if primitive? (primitive rule (car evaluated args) (cdr evaluated args)) (procedure rule (car evaluated args) (cdr evaluated args)))))) Procedure Rule (procedure rule) The procedure rule calls subst to perform the needed substitutions according to the new procedure rule given in the handout, and the calls evaluate on the resulting form. ==========> old Procedure Rule (define procedure rule (lambda (lambda form args) (set! indent (+ indent 1)) (output (format "[Procedure Rule]") #t #t) (let ((result (evaluate (subst lambda form args)))) (set! indent ( indent 1)) result))) in the global environment. Note, if the name is already there it is simply updated using set cdr! Note, nothing stops this evaluator from having define forms that are not at the top level... just don t do that! ==========> old Define Rule (define define rule (lambda (name form) (output (format "[Define Rule]") #f #t) (let ((value (evaluate form)) (pair (assv name global env))) (set cdr! pair value) (set! global env (cons (cons name value) global env)))))) =========> new Define Rule (define define rule (lambda (name form env) (output (format "[Define Rule]") #f #t) (let ((value (evaluate form env)) (pair (lookup in environment name global env #f))) (set cdr! pair value) (set car! global env (append (car global env) (list (cons name value)) )))))) If Rule (if rule) Evaluates the boolean expression and based on the value evaluates either the true form or the false form. An if form is really a special kind of form called a special form because the word if is not evaluated. The same is true for a define form, the keyword define is not evaluated. =========> old If Rule (define if rule (lambda (test form true form false form) (output (format "[If Rule]") #f #t) (if (evaluate test form) (evaluate true form) (evaluate false form)))) Page 6/11 ==========> new Procedure Rule Instead of substituting we now simply call evaluate with the environment in which we wish to evaluate the application of the procedure. This environment if a new environment where the actual parameters are bound to the formal one s, and the parent environment is the one passed in (define procedure rule (lambda (lambda form args) (set! indent (+ indent 1)) (output (format "[Procedure Rule]") #t #t) (let* ((env (cadddr lambda form)) (new env (make new environment (map cons (cadr lambda form) args) env )) (result (evaluate (caddr lambda form) new env))) (set! indent ( indent 1)) result))) Define Rule (define rule) Evaluates the argument and binds the value of the argument to the name =========> new If Rule We need an environment here too! (define if rule (lambda (test form true form false form env) (output (format "[If Rule]") #f #t) (if (evaluate test form env) (evaluate true form env) (evaluate false form env)))) Begin Rule rule) All arguments are evaluated in order, and the value of the last evaluated form is returned. A begin form is special too, the keyword begin is not evaluated. =========> old Begin Rule (define begin rule (lambda (cmd list) (output (format "[Begin Rule]") #f #t) (car (reverse (map evaluate cmd list))))) 3/6

4 Page 7/11 ==========> new Begin Rule We need an environment here too. (define begin rule (lambda (cmd list env) (output (format "[Begin Rule]") #f #t) (let ((result (car (reverse (map (evaluate form env)) cmd lis t))))) result))) (letrec () b) => b) (letrec ((n1 b1)) b) ==> (let ((n1 #f)) (set! n1 b1) b)) (letrec ((n1 b1)... (nk bk)) b) => (let ((n1 #f)) (set! n1 b1) (letrec ((n2 b2)... (nk bk)) b)) Page 8/11 Let Rule (let rule) Rewrite (let ((n1 v1)... (nk vk) body) to ((lambda (n1... nk) body) v1... vk) (define let rule (lambda (let form env) (let ((n1 f1)... (nk fk) b) (output (format "[Let Rule]") #f #t) (let ((binding list (cadr let form))) (if (null? binding list) (evaluate (cons begin (cddr let form)) env) (let () b) => (be gin b) (evaluate (cons (append (list lambda ((λ (map car binding list)) (n1 n2... nk) (cddr let form)) b (map cadr binding list)) env))))) ) f1 f2... fk) (define ll (let ((f #f)) (set! f (lambda (x) (if (= x 0) 1 (* x (f ( x 1)))))) (f 4))) Let* Rule (let* rule) Rewrite (let* ((n1 v1)... (nk vk)) body) according to this: (let* () body) := body ;; (let* ((n v)) body) := (let ((n v )) body) (let* ((n1 v1)... (nk vk)) body) := (let ((n1 v1)) (let* ((n2 v2)... (nk vk)) body)) and then evaluate the new nested lambda forms/applications (define let* helper (lambda (let* form) (let ((binding list (cadr let* form))) (if (= 1 (length binding list)) (append (list let binding list) (cddr let* form)) (list let (list (car binding list)) (let* helper (append (list let* (cdr binding list)) (cddr let* form)))))))) (define let* rule (lambda (let* form env) (output (format "[Let* Rule]") #f #t) (if (null? (cadr let* form)) (evaluate (cons begin (cddr let* form)) env) (evaluate (let* helper let* form) env)))) Letrec Rule (letrec rule) (define letrec rule (lambda (letrec form env) (output (format "[Letrec Rule]") #f #t) ;; your code here! ) ) Set! Rule (set! rule) calls the helper set in environment, which is a simple modification of the deep search function that instead of returning a pair sets the cdr of it to the new value. (define set! rule (lambda (set! form env trace?) (output (format "[Set! Rule]") #f #t) (let ((name (cadr set! form)) (value (evaluate (caddr set! form) env))) (if (set in environment name env value trace?) (void) (display (format "set!: cannot set undefined identifier: ~a" name)) (loop)))))) ======================================= ====== END OF RULE IMPLEMENTATION ===== ======================================= ======================================== ===== THE MAIN EVALUATOR FUNCTIONS ===== ======================================== We need to carry an environment around when we evaluate. (define evaluate (lambda (cmd env) ; function application, primitive application or function definition? (output (format "evaluating ~a in ~a " cmd (pretty environment env)) #t #f) (if (list? cmd) can be one of: define, lambda, if, begin, or an application (case (car cmd) ((define) (define rule (cadr cmd) (caddr cmd) global env)) ((lambda) (output (format "=> #<procedure>") #f #t) (lambda rule cmd env))) ((if) (if rule (cadr cmd) (caddr cmd) (cadddr cmd) env)) () rule (cdr cmd) env)) ((let) (let rule cmd env)) ((let*) (let* rule cmd env)) ((letrec) (letrec rule cmd env)) ((set!) (set! rule cmd env #t)) (else If not one of define, lambda, if, begin, le /let*, or set! then application 4/6

5 Page 9/11 string (output (format "[Application Rule]") #f #t) (application rule cmd env)))) (if (or (boolean? cmd) (string? cmd) (number? cmd)) (literal rule cmd) If the command is a boolean, a number or a (name rule cmd env))))) else it must be a name ===== SYNTAX CHECKING PROCEDURES ===== ====================================== (define is form? (lambda (exp) (syntax check exp))) Page 10/11 The main read evaluate print loop (loop) 1. Read a form 2. Syntax check and evaluate 3. Print the result and recurse ==========> new loop added the global environment to the call to evaluate. (define loop (lambda () (set! indent 0) (display "> ") (let ((command (read))) (if (eq? command stop) #t (if (and (list? command) (> (length command) 0) (eq? (car command) t race)) switches tracing on and off (set! tracing (eq? (cadr command) on)) (loop)) (if (not (syntax check command)) check the syntax (or at le ast try!) (display (format "~a: ~a" type error msg)) (loop)) (let ((result (evaluate command global env))) everythin g was good, now evaluate (if (not (void? result)) (if (string? result) (display (format "Result: \"~a\"" result)) string look better with " " around (display (format "Result: ~a" result)))) (set! indent 0) (loop))))))))) (define is param list? (lambda (lst) (fold (lambda (x y) (and x y)) (map is name? lst) #t))) This is how you apply with and and or ; ) (define is name? (if (and (symbol? form) (not (number? form))) #t (set error msg (format "Not an identifier ~a." form))))) (define is lambda? (set! type "lambda") (if (not (= (length form) 3)) (set error msg (format "bad syntax in: ~a" form)) (if (not (is param list? (cadr form))) #f (if (not (is form? (caddr form))) (set error message (format "bad syntax (not a form) in: ~a" (caddr form))) #t))))) (define is begin? (set! type "begin") (fold (lambda (x y) (and x y)) (map is form? (cdr form)) #t))) (define is define? (set! type "define") (if (not (= (length form) 3)) (set error msg (format "bad syntax (multiple expression after identifier in: ~a" form)) (if (not (is name? (cadr form))) (set error msg (format "bad syntax in: ~a" (cadr form))) (if (not (is form? (caddr form))) (set error msg (format "bad syntax (not a form) in: ~a" (caddr form))) #t))))) =============================================== ===== END OF THE MAIN EVALUATOR FUNCTIONS ===== =============================================== ============================ ===== HELPER FUNCTIONS ===== ============================ fold fold is a version of apply that allows you to specify the neutral element. Example:(foldr f (a b c d) e) = f(f(f(f(e d) c) b) a) This is _really_ foldl for fold left because the neutral element and the recursion is left associative (define fold (lambda (f lst e) (if (null? lst) e (f (fold f (cdr lst) e) (car lst))))) ====================================== (define is if? (set! type "if") (if (not (= (length form) 4)) (set error msg (format "bad syntax in: ~a" form)) (if (not (is form? (cadr form))) (set error msg (format "bad syntax (not a form) in: ~a" (cadr form))) (if (not (is form? (caddr form))) (set error msg (format "bad syntax (not a form) in: ~a" (caddr form))) (if (not (is form? (cadddr form))) (set error msg (format "bad syntax (not a form) in: ~a" (caddr form)) ) #t)))))) (define is application? (fold (lambda (x y) (and x y)) (map is form? form) #t))) (define is binding list? (lambda (form lst) (if (not (list? lst)) (set error msg (format "bad syntax in: ~a" form)) (if (null? lst) #t 5/6

6 Page 11/11 )))) (let ((be (car lst))) (if (not (symbol? (car be))) (set error msg (format "bad syntax (not an identifier) in ~a" (car be))) (and (is form? (cadr be)) (is binding list? form (cdr lst))))) (define is let? (if (not (list? form)) (set error message (format "bad syntax in: ~a" form)) (set! type (car form)) (if (< (length form) 3) (set error message (format "bad syntax in: ~a" form)) (and (is binding list? form (cadr form)) (is form? (cons begin (cddr form))))))))) (define is let*? (is let? form))) (define is letrec? (is let? form))) (define syntax check (if (list? form) (if (= (length form) 0) (set! type "application") (set error msg (format "bad syntax in: ~a" form))) (case (car form) ((define) (is define? form)) ((lambda) (is lambda? form)) ((if) (is if? form)) () (is begin? form)) ((let) (is let? form)) ((letrec) (is letrec? form)) ((let*) (is let*? form)) (else (is application? form)))) (or (number? form) ;; numbers (symbol? form) ;; names (string? form) ;; (boolean? form))))) ======================================== ===== END OF SYNTAX CHECKING RULES ===== ======================================== (init rule) initialize (loop) GO! 6/6

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

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

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

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 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

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

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

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

CSc 520 Principles of Programming Languages. Examining Lists. Constructing Lists... 7: Scheme List Processing

CSc 520 Principles of Programming Languages. Examining Lists. Constructing Lists... 7: Scheme List Processing Constructing Lists CSc 520 Principles of Programming Languages 7: Scheme List Processing Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona The most important

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

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

Important Example: Gene Sequence Matching. Corrigiendum. Central Dogma of Modern Biology. Genetics. How Nucleotides code for Amino Acids

Important Example: Gene Sequence Matching. Corrigiendum. Central Dogma of Modern Biology. Genetics. How Nucleotides code for Amino Acids Important Example: Gene Sequence Matching Century of Biology Two views of computer science s relationship to biology: Bioinformatics: computational methods to help discover new biology from lots of data

More information

ALISP interpreter in Awk

ALISP interpreter in Awk ALISP interpreter in Awk Roger Rohrbach 1592 Union St., #94 San Francisco, CA 94123 January 3, 1989 ABSTRACT This note describes a simple interpreter for the LISP programming language, written in awk.

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

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

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

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream?

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? STREAMS 10 COMPUTER SCIENCE 61AS Basics of Streams 1. What is a stream? A stream is an element and a promise to evaluate the rest of the stream. Streams are a clever idea that allows one to use sequence

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

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

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

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 2005 Project 5 - The Meta-Circular

More information

Text File Databases. Contents. Appendices 7 Source code... 7 Test code Input file readers

Text File Databases. Contents. Appendices 7 Source code... 7 Test code Input file readers Text File Databases Contents 1 Input file readers 1 1.1 Fixed-length data fields............ 2 1.2 Character-delimited fields........... 2 1.3 Comma-separated values............ 2 1.4 Name-value data................

More information

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5 - The Meta-Circular

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

Pattern Matching for Scheme

Pattern Matching for Scheme Pattern Matching for Scheme Andrew K. Wright March 1996 Department of Computer Science MS 132 Rice University 6100 Main Street Houston, Texas 77005-1892 Contents 1 Match 1 1.1 Definition... 1 1.1.1 Patterns...

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

Review Analyzing Evaluator. CS61A Lecture 25. What gets returned by mc-eval? (not analyzing eval) REVIEW What is a procedure?

Review Analyzing Evaluator. CS61A Lecture 25. What gets returned by mc-eval? (not analyzing eval) REVIEW What is a procedure? 2 1 Review Analyzing Evaluator CS61A Lecture 2011-08-02 Colleen Lewis What s look like What the output of analyze was Fact: The body of a lambda gets analyzed! We can give names to analyzed lambdas What

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

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

Begin at the beginning

Begin at the beginning Begin at the beginning Expressions (Syntax) Exec-time Dynamic Values (Semantics) Compile-time Static Types 1. Programmer enters expression 2. ML checks if expression is well-typed Using a precise set of

More information

Assignment 1. Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do

Assignment 1. Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do University of Toronto Mississauga CSC 324 - Principles of Programming Languages, Fall 2016 Assignment 1 Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do The questions below

More information

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes CSE 130 : Fall 2007 Programming Languages News PA deadlines shifted PA #2 now due 10/24 (next Wed) Lecture 5: Functions and Datatypes Ranjit Jhala UC San Diego Recap: Environments Phone book Variables

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

Fall Semester, Lecture Notes { September 26, Today's lecture will use the Henderson Picture Language as an example of how we can merge

Fall Semester, Lecture Notes { September 26, Today's lecture will use the Henderson Picture Language as an example of how we can merge 1 MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 1996 Lecture Notes { September 26,

More information

Programming Languages

Programming Languages CSE 130 : Winter 2009 Programming Languages News PA 2 out, and due Mon 1/26 5pm Lecture 5: Functions and Datatypes t UC San Diego Recap: Environments Phone book Variables = names Values = phone number

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

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 61A Summer 2014 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS ˆ You have 3 hours to complete the exam. ˆ The exam is closed book, closed notes, and closed electronics,

More information

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g))

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g)) CS61A Notes 02b Fake Plastic Trees Box and Pointer Diagrams QUESTIONS: Evaluate the following, and draw a box-and-pointer diagram for each. (Hint: It may be easier to draw the box-and-pointer diagram first.)

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

9 Objects and Classes

9 Objects and Classes 9 Objects and Classes Many programming tasks require the program to manage some piece of state through an interface. For example, a file system has internal state, but we access and modify that state only

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

JScheme : A Scheme Interpreter Embedded Within Java Source Code

JScheme : A Scheme Interpreter Embedded Within Java Source Code JScheme : A Scheme Interpreter Embedded Within Java Source Code CPSC 511 Term Project by Jeff Sember Abstract Mixing two or more programming languages together within a single project can be nontrivial,

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

Tail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial

Tail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial Begin at the beginning Epressions (Synta) Compile-time Static Eec-time Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is well-typed Using a precise set of rules,

More information

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31 Generative and accumulative recursion Readings: Sections 25, 26, 27, 30, 31 Some subsections not explicitly covered in lecture Section 27.2 technique applied to strings CS 135 Fall 2017 11: Generative

More information

Lecture #2 Kenneth W. Flynn RPI CS

Lecture #2 Kenneth W. Flynn RPI CS Outline Programming in Lisp Lecture #2 Kenneth W. Flynn RPI CS Items from last time Recursion, briefly How to run Lisp I/O, Variables and other miscellany Lists Arrays Other data structures Jin Li lij3@rpi.edu

More information

CMSC 331 Final Exam Section 0201 December 18, 2000

CMSC 331 Final Exam Section 0201 December 18, 2000 CMSC 331 Final Exam Section 0201 December 18, 2000 Name: nswers Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points

More information

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012 COMPUTER SCIENCE IN THE NEWS CS6A Lecture 2 Scheme Jom Magrotker UC Berkeley EECS July 24, 202 http://spectrum.ieee.org/tech talk/robotics/artificial intelligence/a texas hold em tournament for ais 2 TODAY

More information

A Genetic Algorithm Implementation

A Genetic Algorithm Implementation A Genetic Algorithm Implementation Roy M. Turner (rturner@maine.edu) Spring 2017 Contents 1 Introduction 3 2 Header information 3 3 Class definitions 3 3.1 Individual..........................................

More information

6.001 recitation 3/21/07

6.001 recitation 3/21/07 6.001 recitation 3/21/07 set-car! and set-cdr! ring problems more set-car!, set-cdr! problems 2 Dr. Kimberle Koile compound data mutation constructor: (cons x y) creates a new pair selectors: (car p) (cdr

More information

CPSC 311, 2010W1 Midterm Exam #2

CPSC 311, 2010W1 Midterm Exam #2 CPSC 311, 2010W1 Midterm Exam #2 2010/11/02 Page 1 of 18 CPSC 311, 2010W1 Midterm Exam #2 Name: Q1: 20 Student ID: Q2: 20 Signature (required; indicates agreement with rules below): Q3: 20 Q4: 20 Q5: 20

More information

Recap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions

Recap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions Recap Epressions (Synta) Compile-time Static Eec-time Dynamic Types (Semantics) Recap Integers: +,-,* floats: +,-,* Booleans: =,

More information

PostFix. PostFix command semanccs (except exec) PostFix Syntax. A PostFix Interpreter in Racket. CS251 Programming Languages Fall 2017, Lyn Turbak

PostFix. PostFix command semanccs (except exec) PostFix Syntax. A PostFix Interpreter in Racket. CS251 Programming Languages Fall 2017, Lyn Turbak PostFix A PostFix Interpreter in Racket CS251 Programming Languages Fall 2017, Lyn Turbak Department of Computer Science Wellesley College PostFix is a stack-based mini-language that will be our first

More information

Redex: Practical Semantics Engineering

Redex: Practical Semantics Engineering Redex: Practical Semantics Engineering Version 4.2.3 Robert Bruce Findler and Casey Klein December 1, 2009 PLT Redex consists of a domain-specific language for specifying reduction semantics, plus a suite

More information

CS1102: Adding Error Checking to Macros

CS1102: Adding Error Checking to Macros CS1102: Adding Error Checking to Macros Kathi Fisler, WPI October 8, 2004 1 Typos in State Machines The point of creating macros for state machines is to hide language details from the programmer. Ideally,

More information

6.001, Spring Semester, 1998, Final Exam Your Name: 2 Question 1 (12 points): Each of the parts below should be treated as independent. For each part,

6.001, Spring Semester, 1998, Final Exam Your Name: 2 Question 1 (12 points): Each of the parts below should be treated as independent. For each part, 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 1998, Final Exam Your Name: Open

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

Decision Making in C

Decision Making in C Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed

More information

Project 1: Part 1. x = b± b 2 4ac., x 2 = b b 2 4ac.

Project 1: Part 1. x = b± b 2 4ac., x 2 = b b 2 4ac. Project 1: Part 1 Project 1 will be to calculate orthogonal polynomials. It will have several parts. Note: The scheme code in this writeup is available in the file project1.scm, available from the course

More information

Meanings of syntax. Norman Ramsey Geoffrey Mainland. COMP 105 Programming Languages Tufts University. January 26, 2015

Meanings of syntax. Norman Ramsey Geoffrey Mainland. COMP 105 Programming Languages Tufts University. January 26, 2015 Meanings of syntax Norman Ramsey Geoffrey Mainland COMP 105 Programming Languages Tufts University January 26, 2015 (COMP 105) Meanings of syntax January 26, 2015 1 / 33 What is the meaning of a while

More information

Problems 3-1, 3.3, 3.4 and 3.5 in Chapter 3 of Winston and Horn's LISP (see Below)

Problems 3-1, 3.3, 3.4 and 3.5 in Chapter 3 of Winston and Horn's LISP (see Below) Homework Solutions: Problem Set Homework 2 Due uesday September 8, 2015 in class Be sure to follow the guidelines for Programming Assignments. Since these problems are simple, you may skip the Statement

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

mk-convert Contents 1 Converting to minikanren, quasimatically. 08 July 2014

mk-convert Contents 1 Converting to minikanren, quasimatically. 08 July 2014 mk-convert 08 July 2014 Contents 1 Converting to minikanren, quasimatically. 1 1.1 Variations on a Scheme..................... 2 1.2 Racket to minikanren, nally.................. 8 1.3 Back to the beginning......................

More information

CSE 114 Computer Science I

CSE 114 Computer Science I CSE 114 Computer Science I Iteration Cape Breton, Nova Scotia What is Iteration? Repeating a set of instructions a specified number of times or until a specific result is achieved How do we repeat steps?

More information

Using closures for code generation

Using closures for code generation Using closures for code generation Marc Feeley Guy Lapalme Département d informatique et de recherche opérationnelle (I.R.O.) Université demontréal P.O.B. 6128, Station A Montréal, Québec, H3C 3J7 (Canada)

More information

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = Hello; Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

More information

Racket Values. cons Glues Two Values into a Pair. The Pros of cons: Programming with Pairs and Lists. Box-and-pointer diagrams for cons trees

Racket Values. cons Glues Two Values into a Pair. The Pros of cons: Programming with Pairs and Lists. Box-and-pointer diagrams for cons trees The Pros of cons: Programming with CS251 Programming Languages Fall 2017, Lyn Turbak Department of Computer Science Wellesley College booleans: #t, #f numbers: integers: 42, 0, -273 ra3onals: 2/3, -251/17

More information

Working with recursion

Working with recursion Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

1998 Midterm and Solutions

1998 Midterm and Solutions 6.821 Programming Languages Handout Fall 2002 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science 1998 Midterm and Solutions There are four problems on this

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 61A Fall 2016 Structure and Interpretation of Computer Programs Final INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except

More information

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 Exercise 1. Consider the if-then-else construct of Pascal, as in the following example: IF 1 = 2 THEN PRINT X ELSE PRINT Y (a) Assume

More information

Project 4 Due 11:59:59pm Thu, May 10, 2012

Project 4 Due 11:59:59pm Thu, May 10, 2012 Project 4 Due 11:59:59pm Thu, May 10, 2012 Updates Apr 30. Moved print() method from Object to String. Apr 27. Added a missing case to assembler.ml/build constants to handle constant arguments to Cmp.

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

Quote of the Day. CS Functional Programming. Introductory Notes on Lisp/Clojure. Another Quote. What is Clojure? 1-4

Quote of the Day. CS Functional Programming. Introductory Notes on Lisp/Clojure. Another Quote. What is Clojure? 1-4 Quote of the Day CS 326 - Functional Programming Introductory Notes on Lisp/Clojure Dr. Stephen P. Carl By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more

More information

Func+on applica+ons (calls, invoca+ons)

Func+on applica+ons (calls, invoca+ons) Func%ons in Racket Racket Functions: most important building block in Racket (and 25) Functions/procedures/methods/subroutines abstract over computations Like Java methods, Python functions have arguments

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 6.9 Sam Tobin-Hochstadt ăsamth@racket-lang.orgą, Vincent St-Amour ăstamourv@racket-lang.orgą, Eric Dobson ăendobson@racket-lang.orgą, and Asumu Takikawa ăasumu@racket-lang.orgą

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Fall 206 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

COMPUTING TYPES DURING PROGRAM SPECIALIZATION

COMPUTING TYPES DURING PROGRAM SPECIALIZATION COMPUTING TYPES DURING PROGRAM SPECIALIZATION Daniel Weise Erik Ruf Technical Report: CSL-TR-90-441 October 1990 This research has been supported in part by NSF Contract No. MIP-8902764, and in part by

More information

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 Goals of this tutorial You should be able to... understand

More information

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Following the Grammar

Following the Grammar Following the Grammar Gary T. Leavens TR #05-02a February 2005, Revised January 2006 Keywords: Recursion, programming recursive procedures, recursion pattern, inductive definition, BNF grammar, Kleene

More information

Trees. Readings: HtDP, sections 14, 15, 16.

Trees. Readings: HtDP, sections 14, 15, 16. Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Common File System Commands

Common File System Commands Common File System Commands ls! List names of all files in current directory ls filenames! List only the named files ls -t! List in time order, most recent first ls -l! Long listing, more information.

More information

Common Lisp. Blake McBride

Common Lisp. Blake McBride Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates

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

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function CSE 130 : Fall 2011 Recap from last time Programming Languages Lecture 3: Data Types Ranjit Jhala UC San Diego 1 2 A shorthand for function binding Put it together: a filter function # let neg = fun f

More information

A Tour of the Cool Support Code

A Tour of the Cool Support Code A Tour of the Cool Support Code 1 Introduction The Cool compiler project provides a number of basic data types to make the task of writing a Cool compiler tractable in the timespan of the course. This

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

ENVIRONMENT DIAGRAMS AND RECURSION 2

ENVIRONMENT DIAGRAMS AND RECURSION 2 ENVIRONMENT DIAGRAMS AND RECURSION 2 COMPUTER SCIENCE 61A February 4, 2016 1 Environment Diagrams An environment diagram keeps track of all the variables that have been defined and the values they are

More information

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

6.001 Recitation 23: Register Machines and Stack Frames

6.001 Recitation 23: Register Machines and Stack Frames 6.001 Recitation 23: Register achines and Stack Frames RI: Gerald Dalley, dalleyg@mit.edu, 8 ay 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ iscellany apply: See the IT Scheme documentation for

More information

CMSC330. Objects, Functional Programming, and lambda calculus

CMSC330. Objects, Functional Programming, and lambda calculus CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

A control expression must evaluate to a value that can be interpreted as true or false.

A control expression must evaluate to a value that can be interpreted as true or false. Control Statements Control Expressions A control expression must evaluate to a value that can be interpreted as true or false. How a control statement behaves depends on the value of its control expression.

More information

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm CIS 110 Introduction to Computer Programming 8 October 2013 Midterm Name: Recitation # (e.g., 201): Pennkey (e.g., eeaton): My signature below certifies that I have complied with the University of Pennsylvania

More information

CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College

CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College A PostFix Interpreter in Racket CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College PostFix PostFix is a stack- based mini- language that will be our first

More information

Assignment 7: functions and closure conversion

Assignment 7: functions and closure conversion Assignment 7: functions and closure conversion ECEN 4553 & 5013, CSCI 4555 & 5525 Prof. Jeremy G. Siek October 20, 2007 The main ideas for this week are: first-class functions lexical scoping of variables

More information

Code example: sfact SICP Explicit-control evaluator. Example register machine: instructions. Goal: a tail-recursive evaluator.

Code example: sfact SICP Explicit-control evaluator. Example register machine: instructions. Goal: a tail-recursive evaluator. 6.001 SICP Explicit-control evaluator Big ideas: how to connect evaluator to machine instructions how to achieve tail recursion Obfuscation: tightly optimized instruction sequence Background eval-dispatch

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