CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

Similar documents
CS 61A Midterm #2 - October 5, 1998

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

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

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

Computer Science Spring 98 Midterm Examination Professor L. Rowe

CS 61B, Summer 2001 Midterm Exam II Professor Michael Olan

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

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy


CS61B, Fall 1995 Midterm #2 K. Yelick

CS184, Fall 1997 Midterm #1 Professor Brian A. Barksy

Discussion 4. Data Abstraction and Sequences

CS 170, Spring 2000 Midterm #1 Professor M. Clancy

CS162, Spring/1992 Midterm #2 Professor Thomas Anderson

CS 61B, Spring 1999 MT3 Professor M. Clancy

CS 314 Principles of Programming Languages. Lecture 16

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

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

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

Sample Final Exam Questions

CS61A Midterm 2 Review (v1.1)

CS 184, Fall 1996 Midterm #1 Professor: unknown

CS 186, Fall 1999 Midterm 2 Professor Hawthorn

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley

CS 61C, Midterm #2, Spring 1997 CS 61C. Spring 1997 Midterm #2. Professor Brian Harvey

EE 122, Spring 1997 Midterm #2 Professor Edell

A Brief Introduction to Scheme (II)

CS 314 Principles of Programming Languages

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

CSE413 Midterm. Question Max Points Total 100

6.001 recitation 3/21/07

CS450 - Structure of Higher Level Languages

Building a system for symbolic differentiation

This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

Write a procedure powerset which takes as its only argument a set S and returns the powerset of S.

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

Programming Languages

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

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

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Building a system for symbolic differentiation

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

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

Computer Science Foundations of Computer Graphics

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

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

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

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

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

Discussion section number. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z

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

Structure and Interpretation of Computer Programs

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

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

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

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

Warm-up! CS 3 Final Review. Predict the output. Predict the Output. Predict the output. Predict the output. What is your favorite color?

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

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

University of Massachusetts Lowell

An Explicit-Continuation Metacircular Evaluator

User-defined Functions. Conditional Expressions in Scheme

Midterm Examination (Sample Solutions), Cmput 325

CMPT 125: Practice Midterm Answer Key

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

Functional Programming - 2. Higher Order Functions

CS61A Notes Disc 11: Streams Streaming Along

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

CS 360 Programming Languages Day 14 Closure Idioms

Quiz 1. Queues , Fall 2007 Recitation 10 Solutions 1

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

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

Structure and Interpretation of Computer Programs

FP Foundations, Scheme

Simplifying Logical Formulas

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

Introduction to Scheme

Lecture #24: Programming Languages and Programs

Scheme Quick Reference

Administrivia. Simple data types

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

CS 184, Fall 1992 MT Solutions Professor Brian A. Barsky

CS 1101 Exam 3 A-Term 2013

UMBC CMSC 331 Final Exam

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

Structure and Interpretation of Computer Programs

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

Introduction to Functional Programming

Lisp Basic Example Test Questions

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

CS 164, Midterm #2, Spring O, M, C - e1 : Bool O, M, C - e2 : t2 O, M, C - e2 : T3 O, M, C - if e1 then e2 else e3 fi : T2 _ T3

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE,

TAIL RECURSION, SCOPE, AND PROJECT 4 11

Scheme Quick Reference

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

Berkeley Scheme s OOP

Project 2: Scheme Interpreter

Transcription:

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey Problem #1 (3 points) What will Scheme print in response to the following expressions? If an expression produces an error message, you may just say "error"; you don't have to provide the exact text of the message. If the value of an expression is a procedure, just say "procedure"; you don't have to show the form in which Scheme prints procedures. Also, draw a box and pointer diagram of the value produced by each expression. (let ((x '(a b c))) (cons (cdr x) (car x))) (cdar '((1 2 3) (4 5 6))) (append (cons '(a) '(b)) (list 'c 'd)) Problem #2 (2 points) file:///c /Documents%20and%20Settings/Jason%20Raft...-%20Fall%201999%20-%20Harvey%20-%20Midterm%201.htm (1 of 5)1/27/2007 6:28:47 PM

Suppose that you have a procedure (f n) that requires time theta(n) and a procedure (g n) that requires theta(n^2). What is the order of growth required for a program to compute (* (f n) (g n))? There may be more than one correct answer; check all that are correct. A. theta(n) B. theta(n^2) C. theta(n + n^2) D. theta(n^3) Problem #3 (2 points) Given the primitive procedure random discussed in lecture, and the procedure square defined as follows: (define (square x) (* x x)) Which of the following expressions may have a different value depending on whether applicative order or normal order is used? There may be more than one correct answer; check all that are correct. A. (random 10) B. (* (random 10) (random 10)) C. (square (random 10)) D. (random (square 10)) file:///c /Documents%20and%20Settings/Jason%20Raft...-%20Fall%201999%20-%20Harvey%20-%20Midterm%201.htm (2 of 5)1/27/2007 6:28:47 PM

Problem #4 (4 points) This question concerns the twenty-one game used in the first programming project. Now that we know about data abstraction, we want to improve the project by using an abstract data type for cards, with the following constructor and selector: (define make-card word) (define card-rank butlast) (define card-suit last) Respect the data abstraction in the procedures you write -- use the constructor and selectors wherever appropriate. (a) Write the strategy procedure want-jack that asks for an additional card unless the player's hand contains a jack. (Yes, this is a very bad strategy.) (b) Write a procedure want-rank that takes a rank as its argument and returns a strategy procedure that asks for an additional card unless the player's hand contains a card of that rank. So the expression (wantrank 'j) should return a strategy equivalent to want-jack above. Problem #5 (4 points) file:///c /Documents%20and%20Settings/Jason%20Raft...-%20Fall%201999%20-%20Harvey%20-%20Midterm%201.htm (3 of 5)1/27/2007 6:28:47 PM

Consider the abstract data type Crisp that includes three components: a Snap, a Crackle, and a Pop. The constructor for this ADT is: (define (make-crisp s c p) (cons (list sc) p)) (a) Write the three selectors snap, crackle, pop that take a Crisp as argument and return the appropriate component. (b) Write a procedure rotate-crisp that takes a Crisp as its argument (hereafter called c) and returns a new Crisp whose Snap is the Crackle of c, whose Crackle is the Pop of c, and whose Pop is the Snap of c. Respect the data abstraction. Problem #6 (4 points) (a) Complete the following procedure sentence? that takes any Scheme value as its argument and returns #T if the argument is a sentence, or #F otherwise. In order to be a sentence, the argument must be a list, and every element of the list must be a word. You may use the primitive procedure word? in your solution. (define (sentence? x) (cond ((null? x) ) ((not (pair? x)) ) ( #F) (else ))) (b) Write a procedure list-of-sentences? that takes any Scheme value as its argument, and returns #T if the argument is a list of sentences, or #F otherwise. In order to be a list of sentences, the argument must be a list, and every element of the list must be a sentence. file:///c /Documents%20and%20Settings/Jason%20Raft...-%20Fall%201999%20-%20Harvey%20-%20Midterm%201.htm (4 of 5)1/27/2007 6:28:47 PM

(c) Write a procedure list-of-whatevers? that takes two arguments;the first must be a predicate function of one argument, and the second can be any Scheme value. It should return #T if the second argument is a list in which every element satisfies the predicate, or #F otherwise. Posted by HKN (Electrical Engineering and Computer Science Honor Society) University of California at Berkeley If you have any questions about these online exams please contact mailto:examfile@hkn.eecs.berkeley.edu file:///c /Documents%20and%20Settings/Jason%20Raft...-%20Fall%201999%20-%20Harvey%20-%20Midterm%201.htm (5 of 5)1/27/2007 6:28:47 PM