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

Similar documents
6.001: Structure and Interpretation of Computer Programs. Themes to be integrated. Our target the art of M. C. Escher

Today's Lecture. Programming as the process of creating a new task-specific language. data abstractions procedure abstractions higher-order procedures

1. The Square limit language

University of Massachusetts Lowell : Organization of Programming Languages Spring 2004 Problem Set 4. Henderson Picture Language

Why do we need an interpreter? SICP Interpretation part 1. Role of each part of the interpreter. 1. Arithmetic calculator.

6.001, Fall Semester, 1998 Lecture Notes, October 27 { Object Oriented Programming 2 An environment diagram illustrating +define foo +cons 1 2,, +set-

A Brief Introduction to Scheme (II)

CSc 520 Principles of Programming Languages

CS61A Midterm 2 Review (v1.1)

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

Functional Programming. Pure Functional Programming

Syntactic Sugar: Using the Metacircular Evaluator to Implement the Language You Want

Project 2: Scheme Interpreter

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

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

Building a system for symbolic differentiation

Vectors in Scheme. Data Structures in Scheme

Building a system for symbolic differentiation

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

How to Design Programs Languages

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

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

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

An Explicit-Continuation Metacircular Evaluator

2.2 Hierarchical Data and the Closure Property

(scheme-1) has lambda but NOT define

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

Fall Semester, Lecture Notes { November 12, Variations on a Scheme Nondeterministic evaluation

Scheme Quick Reference

Using Symbols in Expressions (1) evaluate sub-expressions... Number. ( ) machine code to add

Guided Problem Solving

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

Lexical vs. Dynamic Scope

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Sample Final Exam Questions

Scheme Quick Reference

6.001, Spring Semester, 1998, Final Exam Solutions Your Name: 2 Part c: The procedure eval-until: (define (eval-until exp env) (let ((return (eval-seq

CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018

University of Massachusetts Lowell

Quiz 1. Queues , Fall 2007 Recitation 10 Solutions 1

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Streams. CS21b: Structure and Interpretation of Computer Programs Spring Term, 2004

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

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

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

Junior Circle Meeting 9 Commutativity and Inverses. May 30, We are going to examine different ways to transform the square below:

CS 275 Name Final Exam Solutions December 16, 2016

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

Discussion 12 The MCE (solutions)

Putting the fun in functional programming

MET 107 Drawing Tool (Shapes) Notes Day 3

University of Virginia, Department of Computer Science cs150: Computer Science Spring 2007 Out: 5 February 2007 Problem Set 3: L-System Fractals

Not really what happens in the computer. The Environment Model. (set-car! l 'z) (car l) z

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name

Documentation for LISP in BASIC

Representing Images as Lists of Spots

6.037 Lecture 7B. Scheme Variants Normal Order Lazy Evaluation Streams

About Finish Line Mathematics 5

Administrivia. Simple data types

PLT Miscellaneous Libraries: Reference Manual

Quadrilaterals & Transformations Study Guide

CS 342 Lecture 6 Scheme Procedures and Closures By: Hridesh Rajan

Creating a 2D Geometry Model

This section provides an overview of the features available within the Standard, Align, and Text Toolbars.

CS 342 Lecture 8 Data Abstraction By: Hridesh Rajan

Creating a Text Frame. Create a Table and Type Text. Pointer Tool Text Tool Table Tool Word Art Tool

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

Introduction to Scheme

PROFESSOR: Well, now that we've given you some power to make independent local state and to model objects,

Maths Grade 2 Knowledge Organiser

SCHEME AND CALCULATOR 5b

Structure and Interpretation of Computer Programs

Defining Recursive Procedures. Lecture 8: Recursing Lists. list? Tracing list? sumlist. Defining Recursive Procedures on Lists

CS 314 Principles of Programming Languages

CS2500 Exam 2 Fall 2011

Project 1: Part 1. Project 1 will be to calculate orthogonal polynomials. It will have several parts. x = b± b 2 4ac., x 2 = b b 2 4ac.

LECTURE 16. Functional Programming

CS 61A Discussion 8: Scheme. March 23, 2017

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

YOUR NAME PLEASE: *** SOLUTIONS ***

To specify the dimensions of the drawing canvas use the size statement: ! size( 300, 400 );

From Syntactic Sugar to the Syntactic Meth Lab:

CS61A Summer 2010 George Wang, Jonathan Kotker, Seshadri Mahalingam, Eric Tzeng, Steven Tang

CS 61A Midterm #2 ver March 2, 1998 Exam version: A. Your name. login: cs61a- Discussion section number. TA's name

;; definition of function, fun, that adds 7 to the input (define fun (lambda (x) (+ x 7)))

6.001 Notes: Section 8.1

CSE413 Midterm. Question Max Points Total 100

Principles of Programming Languages 2017W, Functional Programming

Part 1: Basics. Page Sorter:

Geometry R. Unit 12 Coordinate Geometry. Day Classwork Day Homework Wednesday 3/7 Thursday 3/8 Friday 3/9

Computer Graphics 7: Viewing in 3-D

6.837 LECTURE 7. Lecture 7 Outline Fall '01. Lecture Fall '01

TAIL RECURSION, SCOPE, AND PROJECT 4 11

SketchUp. SketchUp. Google SketchUp. Using SketchUp. The Tool Set

Areas of some geometric gures

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

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

Lisp Basic Example Test Questions

6.945 Adventures in Advanced Symbolic Programming

Transcription:

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, 1996 Henderson Picture Language Today's lecture will use the Henderson Picture Language as an example of how we can merge together the themes of data abstraction, higher order procedures and procedural abstractions to create a new language for describing ures. You will be dealing with this language in Problem Set 4, and much of the background for the language is discussed in Section 2.2.4 of the text. Below is the code we will be using during this lecture to discuss this language. We layer the implementation of the ure language much as in the code we have used in Problem Sets 1, 2 and 3. First, we dene an abstraction for vectors, and primitive operations on vectors: (define make-vect cons) (define xcor car) (define ycor cdr) Here is one simple procedure for manipulating vectors (define (+vect v1 v2) (make-vect (+ (xcor v1) (xcor v2)) (+ (ycor v1) (ycor v2)))) Relate procedures include -vect for subtracting vectors, and scale-vect for scaling a vector by some amount. (define (rotate-vect v angle) (let ((c (cos angle)) (s (sin angle))) (make-vect (- (* c (xcor v)) (* s (ycor v))) We make lines out of vectors: (define make-line list) (define beg car) (define end cadr) We also make rectangles out of vectors: (define make-rectangle list) (define origin car) (define horiz cadr) (+ (* c (ycor v)) (* s (xcor v)))))) (define vert caddr) Finally, we dene ures and some primitives on them:

6.001, Fall Semester, 1996 Lecture Notes { September 26, 1996 2 (define (make-ure seglist) (for-each (lambda (segment) (let ((b (beg segment)) (e (end segment))) (draw-line rect seglist))) (xcor b) (ycor b) (xcor e) (ycor e)))) Note the form of this procedure { it takes a list of segments as input, and returns a procedure { when this procedure is applied to a rectangle, it will draw the segments inside that rectangle. Thus a ure is actually a procedure. We haven't specied draw-line, but for our purposes here, we assume that the list of segments species points in the unit square, and that draw-line draws those segments scaled to t within the specied rectangle. Now we can use these ideas: (define empty-ure (make-ure '())) (define outline-ure (make-ure (list (make-vect 0 0) (make-vect 0 1)) (make-vect 0 1) (make-vect 1 1)) (make-vect 1 1) (make-vect 1 0)) (make-vect 1 0) (make-vect 0 0))))) (define (prim- list-of-lines) (make-ure (map (lambda (line) (make-vect (car line) (cadr line)) (make-vect (caddr line) (cadddr line)))) list-of-lines))) Now we can make a particular ure:

6.001, Fall Semester, 1996 Lecture Notes { September 26, 1996 3 (define g (prim- (list (list.25 0.35 (list.35.5.3.6) (list.3.6.15.4) (list.15.4 0.65) (list.4 0.5.3) (list.5.3.6 0) (list.75 0.6.45) (list.6.45 1.15) (list 1.35.75.65) (list.75.65.6.65) (list.6.65.65.85) (list.65.85.6 1) (list.4 1.35.85) (list.35.85.4.65) (list.4.65.3.65) (list.3.65.15.6) (list.15.6 0.85)))) (define big-bro (beside g (above empty-ure g (define acrobats (beside g (rotate180 (flip g)) (define 4bats (above acrobats (flip acrobats) Here are some operations on ures, others are very similarly dened: (define (rotate90 ) ( (make-rectangle (+vect (origin rect) (vert rect) (horiz rect)) (scale-vect (horiz rect) -1))))) (define (together 1 2) (1 rect) (2 rect)))

6.001, Fall Semester, 1996 Lecture Notes { September 26, 1996 4 (define (flip ) ( (make-rectangle (+vect (origin rect) (horiz rect)) (scale-vect (horiz rect) -1) (vert rect))))) (define (beside 1 2 a) (1 (make-rectangle (origin rect) (scale-vect (horiz rect) a) (vert rect))) (2 (make-rectangle (+vect (origin rect) (scale-vect (horiz rect) a)) (scale-vect (horiz rect) (- 1 a)) (vert rect))))) (define (above 1 2 a) (rotate270 (beside (rotate90 1) (rotate90 2) a)))

6.001, Fall Semester, 1996 Lecture Notes { September 26, 1996 5 (define (repeated function n) (lambda (thing) thing ((repeated function (- n 1)) (function thing))))) (define (4 1 rot1 2 rot2 3 rot3 4 rot4) (beside (above ((repeated rotate90 rot1) 1) ((repeated rotate90 rot2) 2) (above ((repeated rotate90 rot3) 3) ((repeated rotate90 rot4) 4) (define (4same rot1 rot2 rot3 rot4) (4 rot1 rot2 rot3 rot4)) (define (up-push n) (above (up-push (- n 1)) (define (right-push n) (beside (rightp-push (- n 1)) (define (corner-push n) (above (beside (up-push n) (corner-push (- n 1)).75) (beside (right-push (- n 1)).75) (define (square-limit n) (4same (corner-push n) 1 2 0 3))