# Structure and Interpretation of Computer Programs

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 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, except two hand-written 8.5 pages of your own creation and the official CS 6A study guides. Mark your answers on the exam itself. We will not grade answers written on scratch paper. Last name First name Student ID number CalCentral TA Room Row & Seat Number Name of the person to your left Name of the person to your right All the work on this exam is my own. (please sign)

2 2. (6 points) What Would Python Display? For each of the expressions in the table below, write the output displayed by the interactive Python interpreter when the expression is evaluated. The output may have multiple lines. If an error occurs, write Error, but include all output displayed before the error. Assume that expressions are evaluated in the order that they appear on the page, with the left column before the right column. The Pair class appears on page 2 of the final study guide. The reduce function appears on page of the final study guide. The first two rows have been provided as examples. Assume that you have started python and executed the following statements: swap = lambda a, b: [b, a] paws = lambda s: reduce (swap, (s), ) emit = lambda y: [x+y for x in y] time = lambda t, f: (t and f(t)) or print (t +2) mite = lambda mu: time ( mu +, print ) s, t = print, [ * x for x in range ( 8)] def ti(me ): while me: yield time (me, lambda k: [k. pop ()]) def newt ( graves ): tina = graves. pop () if graves. pop () % == 0: graves. pop () print (tina, graves. pop ()) if graves : return Pair (tina -, newt ( graves )) return Pair ( tina +, tina ) Expression Interactive Output 5*5 25 print(pair(6, )) (6. ) print(2, s(print())) None 2 None emit([[], [2]])[] [2, [], [2]] s(pair(pair(4, 5), nil)) time(2, mite) ((4. 5)) 5 4 Expression paws(range(4, 6)) tuple(ti([5, 6])) s(newt([2, 5, 8])) s(newt(t)) Interactive Output [5, [4, ]] ([6], [5]) 8 2 (9. 8) (20. 9)

3 Name: 2. (8 points) A Function By Any Other Name Fill in the environment diagram that results from executing the code below until the entire program is finished, an error occurs, or all frames are filled. You may not need to use all of the spaces or frames. A complete answer will: Add all missing names and parent annotations to frames. Add all missing values created or referenced during execution. Show the return value for each local frame. Use box-and-pointer notation for s. You don t need to write index numbers or the word name = [2, lambda your: name[0]] def your(name): def what(s): nonlocal name name = [name, s] return what is your(name) def your(s): s[][](name[:]) return what your(true)(name) Global frame your name f: your [parent= ] Global name what your func your(name) [parent=global] True 2 func what(s) [parent=f] func your(s) [parent=f] func λ(your) [parent=global] Return Value f2: what [parent= ] f s Return Value False your f f: [parent= ] s Return Value None f4: λ [parent= ] Global your 0 True Return Value 2 Green boxes indicate parts of the diagram that were scored during grading.

4 4. (8 points) Boxes and Arrows Fill in the environment diagram that results from executing each block of code below until the entire program is finished or an error occurs. Use box-and-pointer notation for s. You don t need to write index numbers or the word. Please erase or cross out any boxes or pointers that are not part of a final diagram. (a) t = [] t.append([t, []]) Global frame t 0 (b) t = [, 2] t.append(t[t[0]:t[t[0]]]) Global frame t (c) t = [] t.extend(t + [t] + [[t]]) Global frame t 2 0 (d) t = [, 2,, 4] t[] = t[2:4] t[2:] = t t[4] = t.pop() Global frame t

5 Name: 5 4. (6 points) A Tree or a List A flat is a containing integers and None that describes a binary tree of integers. The root is element 0. The left branch of element i is element 2 i + and the right is 2 i + 2. The None value is used to indicate an empty tree, such as an empty left branch when the corresponding right branch is not empty. None values at the end of a flat can be omitted. Four examples of trees and the flat s that describe them appear below. 4 [,, 4] 4 [, None, 4] [, ] or 6 8 [,, None] 7 [6,, 8,, None, 7] or [6,, 8,, None, 7, None] (a) (4 pt) Implement grow, which takes a flat s of integer node values (which may also contain None, as described above) and an index i that is 0 by default. When i is 0, grow returns a BTree instance described by s. The BTree class appears in the left column of page 2 of the midterm 2 study guide. def grow (s, i =0): """ Return a binary tree described by the flat S when I is 0. >>> grow ([,, 4]) BTree (, BTree (), BTree (4)) >>> grow ([, None, 4]) BTree (, BTree. empty, BTree (4)) >>> grow ([,, None ]) BTree (, BTree ()) >>> grow ([6,, 8,, None, 7]) BTree (6, BTree (, BTree ()), BTree (8, BTree (7))) """ if i >= len (s) or s[i] is None : return BTree. empty left, right = grow (s, 2*i+), grow (s, 2*i+2) return BTree (s[i], left, right ) (b) (4 pt) Implement leaves, which takes a flat s and returns a generator over the leaf values of the tree described by s. You may not call grow in your solution. def leaves (s): """ Return a generator over the leaf values in a binary tree described by S. >>> ( leaves ([,, 4])) [, 4] >>> ( leaves ([,, None ])) [] >>> ( leaves ([6,, 8,, None, 7])) [, 7] """ f = lambda x: x >= len (s) or s[x] is None for i in range ( len (s )): if s[i] is not None and f (2* i +) and f (2* i +2): yield s[i]

8 8 6. (0 points) I Scheme for Ice Cream The built-in append procedure is equivalent in behavior to the following definition. ( define ( append s t) (if ( null? s) t ( cons ( car s) ( append ( cdr s) t )))) (a) ( pt) Circle True or False: The recursive call to append in the definition above is a tail call. (b) (4 pt) Implement atoms, which takes a Scheme expression. It returns a of the non-nil atoms contained in the expression in the order that they appear. A non-nil atom is a number, symbol, or boolean value. scm > ( atoms ) () scm > ( atoms (+ 2 )) (+ 2 ) scm > ( atoms (+ (* 2 ) 4)) (+ * 2 4) scm > ( atoms (* (+ (* 2 )) (+ 4 5))) (* + * ) ( define ( atoms exp ) ( cond (( null? exp ) nil ) (( atom? exp ) ( exp )) ( else ( append ( atoms ( car exp )) ( atoms ( cdr exp )))))) (c) (5 pt) If Scheme had only numbers and two-argument procedures, parentheses would be unnecessary. To demonstrate, implement tally, which takes the of atoms in a Scheme expression. It returns a whose first element is the value of the original expression. Assume that the original expression consists only of numbers and call expressions with arithmetic operators (such as + and *) and exactly two operands. Hint: tally is similar to the built-in eval procedure: (eval (+ (* 2 ) 4)) evaluates to 0. scm > ( car ( tally ())) ; atoms in scm > ( car ( tally (+ 2 ))) ; atoms in (+ 2 ) 5 scm > ( car ( tally (+ * 2 4))) ; atoms in (+ (* 2 ) 4) 0 scm > ( car ( tally (* + * ))) ; atoms in (* (+ (* 2 )) (+ 4 5)) 6 ( define ( tally s) (if ( number? ( car s)) s ( let (( first ( tally ( cdr s )))) ( let (( second ( tally ( cdr first )))) ( cons ( eval ( ( car s) ( car first ) ( car second ))) ( cdr second ))))))

9 Name: 9 7. (2 points) Hailstoned The following two tables of integers from 0 to 99 (including 99) and to 99 are used in the questions below. create table ns as with t( n) as ( select 0 union select n + from t where n < 99 ) select * from t; create table ps as select n from ns where n > 0; (a) ( pt) Create a one-column table of all integers from 2000 to 9999 (including 9999). Do not use recursion. select a. n * 00 + b. n from ns as a, ns as b where a. n >= 20; (b) (5 pt) Create a table with a row for each pair of different positive integers x and y below 00. The three columns contain x, y, and the greatest common divisor of x and y. For example, one row contains (20, 50, 0) because 0 is the largest n that evenly divides both 20 and 50. Another row contains (50, 20, 0). select a.n as x, b.n as y, max (c.n) as gcd from ps as a, ps as b, ps as c where a.n <> b.n and a.n % c.n = 0 and b.n % c.n = 0 group by a.n * 00 + b.n; (c) (4 pt) A hailstone sequence begins with a positive m. If m is even, divide it by 2. If m is odd, triple it and add. Repeat until is reached. For example, the sequence starting at is, 0, 5, 6, 8, 4, 2,. Create a two-column table with positive integer m in the first column and the length of the hailstone sequence starting at m in the second column. For example, one row contains (, 8) because the hailstone sequence starting at has 8 elements. This table should have one row for each m, but only include m for which the entire hailstone sequence starting at m consists of numbers below 00. with hailstone ( m, length ) as ( select, union select n, length + from hailstone, ps where (n %2==0 and m == n /2) or (n > and n %2== and m == *n+) ) select * from hailstone ;

10 0 8. (0 points) Draw! (Optional) Compare Python, Scheme, and SQL in a picture.

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

### Structure and Interpretation of Computer Programs

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

### Structure and Interpretation of Computer Programs

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

### Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

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

### Structure and Interpretation of Computer Programs

CS 61A Summer 2015 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,

### Structure and Interpretation of Computer Programs

CS 61A Spring 2017 Structure and Interpretation of Computer Programs Test 1 Solutions INSTRUCTIONS You have 2 hours to complete the exam. The exam is open book, open notes, closed computer, closed calculator.

### Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

CS 61A Structure and Interpretation of Computer Programs Fall 2015 Midterm 1 INSTRUCTIONS You have 2 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

### Structure and Interpretation of Computer Programs

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

### Structure and Interpretation of Computer Programs

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

### Structure and Interpretation of Computer Programs

CS 61A Fall 2017 Structure and Interpretation of Computer Programs Midterm 1 Solutions INSTRUCTIONS You have 2 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed

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

### Structure and Interpretation of Computer Programs Spring 2015 Midterm 2

CS 61A Structure and Interpretation of Computer Programs Spring 015 Midterm INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

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

### Structure and Interpretation of Computer Programs

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

### Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

CS 6A Structure and Interpretation of Computer Programs Summer 05 Midterm INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except

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

### Structure and Interpretation of Computer Programs Summer 2014 Midterm 2

CS 61A Structure and Interpretation of Computer Programs Summer 2014 Midterm 2 INSTRUCTIONS You have 2 hours to complete the exam. The exam is closed book, closed notes, and closed electronics, except

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

### Structure and Interpretation of Computer Programs

CS 61A Summer 2016 Structure and Interpretation of Computer Programs Midterm Solutions INSTRUCTIONS You have 2 hours and 50 minutes to complete the exam. The exam is closed book, closed notes, closed computer,

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

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

### Structure and Interpretation of Computer Programs

CS 61A Spring 2017 Structure and Interpretation of Computer Programs Test 2 (revised) Solutions INSTRUCTIONS You have 2 hours to complete the exam. The exam is open book, open notes, closed computer, closed

### Delayed Expressions Fall 2017 Discussion 9: November 8, Iterables and Iterators. For Loops. Other Iterable Uses

CS 6A Delayed Expressions Fall 07 Discussion 9: November 8, 07 Iterables and Iterators An iterable is any container that can be processed sequentially. Examples include lists, tuples, strings, and dictionaries.

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

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

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

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

### Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

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

### This exam is worth 30 points, or 18.75% of your total course grade. The exam contains

CS 60A Final May 16, 1992 Your name Discussion section number TA's name This exam is worth 30 points, or 18.75% of your total course grade. The exam contains six questions. This booklet contains eleven

### 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.)

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

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

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

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

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

### University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

### Fall 2017 December 4, 2017

CS 61A Final Review Fall 2017 December 4, 2017 Instructions Form a small group. Start on the first problem. Check off with a helper or discuss your solution process with another group once everyone understands

### Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators

CS 61A Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions 1 Control Control structures direct the flow of logic in a program. For example, conditionals (if-elif-else) allow a program

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

### Midterm Exam 1 Solutions

CS 61A Fall 2011 Structure and Interpretation of Computer Programs Midterm Exam 1 Solutions INSTRUCTIONS You have 2 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed

### Midterm Exam 2B Answer key

Midterm Exam 2B Answer key 15110 Principles of Computing Fall 2015 April 6, 2015 Name: Andrew ID: Lab section: Instructions Answer each question neatly in the space provided. There are 6 questions totaling

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

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

### Structure and Interpretation of Computer Programs

CS 61A Structure and Interpretation of Computer Programs Fall 2011 Midterm Exam 1 INSTRUCTIONS You have 2 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

### CS 1301 Exam 3 Spring 2014

CS 1301 Exam 3 Spring 2014 Name : Section TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam

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

### STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

STREAMS 10 COMPUTER SCIENCE 61AS Basics of Streams 1. What is a stream? 2. How does memoization work? 3. Is a cons-stream a special form? Practice with Streams 1. Define a procedure (ones) that, when run

### Lab Exercise 8 Binary Search Trees

Lab Exercise 8 Binary Search Trees A binary search tree is a binary tree of ordered nodes. The nodes are ordered by some key value, for example: alphabetic or numeric. The left subtree of every node (if

### Outline. An Application: A Binary Search Tree. 1 Chapter 7: Trees. favicon. CSI33 Data Structures

Outline Chapter 7: Trees 1 Chapter 7: Trees Approaching BST Making a decision We discussed the trade-offs between linked and array-based implementations of sequences (back in Section 4.7). Linked lists

### CS 415 Midterm Exam Fall 2003

CS 415 Midterm Exam Fall 2003 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you can to

### CS 2316 Exam 4 Fall 2012

CS 2316 Exam 4 Fall 2012 Name : Section TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

### CS 536 Midterm Exam Spring 2013

CS 536 Midterm Exam Spring 2013 ID: Exam Instructions: Write your student ID (not your name) in the space provided at the top of each page of the exam. Write all your answers on the exam itself. Feel free

### Summer Final Exam Review Session August 5, 2009

15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

### Examination Questions Midterm 2

CS1102s Data Structures and Algorithms 12/3/2010 Examination Questions Midterm 2 This examination question booklet has 6 pages, including this cover page, and contains 12 questions. You have 30 minutes

### MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

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

### GENERATORS AND STREAMS

GENERATORS AND STREAMS COMPUTER SCIENCE MENTORS 61A November 13 to November 17, 2017 1 Generators 1. What does the following code block output? def foo(: a = 0 if a < 10: print("hello" yield a print("world"

### Structure and Interpretation of Computer Programs

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

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

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

### Second Examination Solution

University of Illinois at Urbana-Champaign Department of Computer Science Second Examination Solution CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, November 8 Name: NetID: Lab

### INTERPRETERS 8. 1 Calculator COMPUTER SCIENCE 61A. November 3, 2016

INTERPRETERS 8 COMPUTER SCIENCE 61A November 3, 2016 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that understand other programs. In

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

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

### Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well

### CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm Name: Discussion Time: 10am 11am 12pm 1pm 2pm 3pm TA Name (Circle): Alex Austin Ayman Brian Damien Daniel K. Daniel P. Greg Tammy Tim Vitung Will K. Instructions

### Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Midterm 1: CS186, Spring 2016 Name: Class Login: cs186- You should receive 1 double-sided answer sheet and an 11-page exam. Mark your name and login on both sides of the answer sheet, and in the blanks

### CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, 2011 Name: EID: Section Number: Friday discussion time (circle one): 9-10 10-11 11-12 12-1 2-3 Friday discussion TA(circle one): Wei Ashley Answer

### University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Fall 2011 9a-11a, Wednesday, November 2 Name: NetID: Lab Section

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

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

### HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other?

HIERARCHICAL DATA 5 COMPUTER SCIENCE 61AS Concepts and Definitions 1. What is a Tree? How is it different from a Deep List? When would you use one over the other? A Tree is an Abstract Data Type composed

### CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

### CSC324 Functional Programming Typing, Exceptions in ML

CSC324 Functional Programming Typing, Exceptions in ML Afsaneh Fazly 1 Winter 2013 1 with many thanks to Anya Tafliovich, Gerald Penn, Sheila McIlraith, Wael Aboelsaddat, Tony Bonner, Eric Joanis, Suzanne

### Final Examination CSE 100 UCSD (Practice)

Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam

### Midterm Practice Exam Sample Solutions

Name: SID: CS 620 Theory of Computation Fall 2017 Instructor: Marc Pomplun Midterm Practice Exam Sample Solutions Duration: 1 hour and 15 minutes You only need your writing utensils to complete this exam.

### Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

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

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

### Computer Science Foundation Exam

Computer Science Foundation Exam August 8, 2014 Section I B COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category Passing

### Computer Science Foundation Exam

Computer Science Foundation Exam August 6, 017 Section I A DATA STRUCTURES SOLUTIONS NO books, notes, or calculators may be used, and you must work entirely on your own. Question # Max Pts Category Passing

### CPS 231 Exam 2 SOLUTIONS

CPS 231 Exam 2 SOLUTIONS Fall 2003 1:00-2:25, Tuesday November 20th Closed book exam NAME: Problem Max Obtained 1 10 2 25 3 (a) 15 3 (b) 15 3 (c) 10 4 (a) 10 4 (b) 15 4 (c) 10 Total 110 1 [10 points ]

### CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

### Lisp: Question 1. Dr. Zoran Duric () Midterm Review 1 1/ 13 September 23, / 13

Lisp: Question 1 Write a recursive lisp function that takes a list as an argument and returns the number of atoms on any level of the list. For instance, list (A B (C D E) ()) contains six atoms (A, B,

### CMSC330 Fall 2015 Midterm #1 12:30pm/2:00pm/5:00pm

CMSC330 Fall 2015 Midterm #1 12:30pm/2:00pm/5:00pm Name: Discussion Time: 10am 11am 12pm 1pm 2pm 3pm TA Name (Circle): Adam Maria Chris Chris Michael Candice Amelia Amelia Samuel Josh Max Instructions

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

### Midterm 2 Review Fall 2017 October 13, Lists & Tree Recursion. Instructions

CS 6A Midterm 2 Review Fall 207 October 3, 207 Instructions Form a small group. Start on the first problem. Check off with a helper or discuss your solution process with another group once everyone understands

### Overview of List Syntax

Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates

### Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] SOLUTION. cs186-

Midterm 1: CS186, Spring 2016 Name: Class Login: SOLUTION cs186- You should receive 1 double-sided answer sheet and an 10-page exam. Mark your name and login on both sides of the answer sheet, and in the

### CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 2 A Fall 2015 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam

### Solution to CSE 250 Final Exam

Solution to CSE 250 Final Exam Fall 2013 Time: 3 hours. December 13, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do

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

### A LISP Interpreter in ML

UNIVERSITY OF OSLO Department of Informatics A LISP Interpreter in ML Mandatory Assignment 1 INF3110 September 21, 2009 Contents 1 1 Introduction The purpose of this assignment is to write an interpreter,

### ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

### UMBC CMSC 331 Final Exam Section 0101 December 17, 2002

0 / 0 1 / 20 UMBC CMSC 331 Final Exam Section 0101 December 17, 2002 Name: Student ID#: 2 / 25 3 / 20 4 / 25 5 / 20 6 /40 7 /40 You will have two hours to complete this closed book exam. We reserve the

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

### CS 307 Midterm 2 Spring 2008

Points off 1 2 3 4 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2008 Name UTEID login name TA's Name: Mario Ruchica Vishvas (Circle One) Instructions: 1. Please turn off your cell phones and