CSE413 Midterm. Question Max Points Total 100

Similar documents
CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

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

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

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

CS 415 Midterm Exam Spring SOLUTION

CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination

Discussion 4. Data Abstraction and Sequences

April 2 to April 4, 2018

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

Structure and Interpretation of Computer Programs

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Structure and Interpretation of Computer Programs

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

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

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

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

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

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

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

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

CS 415 Midterm Exam Spring 2002

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

CSE 341 : Programming Languages Midterm, Spring 2015

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

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

Intro. Scheme Basics. scm> 5 5. scm>

ECE264 Fall 2013 Exam 1, September 24, 2013

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

CS61A Midterm 2 Review (v1.1)

Sample Final Exam Questions

Project 2: Scheme Interpreter

Lisp Basic Example Test Questions

CS 415 Midterm Exam Fall 2003

Functional Programming. Pure Functional Programming

CS61A Notes Disc 11: Streams Streaming Along

Midterm Examination (Sample Solutions), Cmput 325

CS 314 Principles of Programming Languages. Lecture 16

CSE 303, Spring 2005, Midterm Examination 29 April Please do not turn the page until everyone is ready.

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

University of Massachusetts Lowell

Repetition Through Recursion

Discussion 11. Streams

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Lexical vs. Dynamic Scope

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

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

CSE 303 Midterm Exam

CSE341, Spring 2013, Final Examination June 13, 2013

Administrivia. Simple data types

Warm-up and Memoization

Comp 311: Sample Midterm Examination

CMSC 331 Final Exam Section 0201 December 18, 2000

SCHEME AND CALCULATOR 5b

Functional Programming. Pure Functional Languages

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

Turtles All The Way Down

CS450 - Structure of Higher Level Languages

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Structure and Interpretation of Computer Programs

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Midterm 2 Solutions Many acceptable answers; one was the following: (defparameter g1

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

Box-and-arrow Diagrams

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE341 Spring 2017, Final Examination June 8, 2017

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

Programming Languages

CSE 142 Wi01 Midterm 2 page 1 of 6

Largest Online Community of VU Students

TAIL RECURSION, SCOPE, AND PROJECT 4 11

Computer Architecture I Midterm I

UMBC CMSC 331 Final Exam

CS 314 Principles of Programming Languages

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

Functional Programming. Pure Functional Languages

YOUR NAME PLEASE: *** SOLUTIONS ***

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Putting the fun in functional programming

ENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;

MIDTERM EXAMINATION - CS130 - Spring 2005


Midterm Review. Short Answer. Short Answer. Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions.

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

CSE 333 Midterm Exam 2/14/14

CSE 413 Winter 2001 Midterm Exam

CS 314 Principles of Programming Languages

CS16 Exam #1 7/17/ Minutes 100 Points total

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

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

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE 143 SAMPLE MIDTERM

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

Documentation for LISP in BASIC

CSE wi: Practice Midterm

Transcription:

CSE413 Midterm 05 November 2007 Name Student ID Answer all questions; show your work. You may use: 1. The Scheme language definition. 2. One 8.5 * 11 piece of paper with handwritten notes Other items, including laptop computers, calculators, cell phones, and other communications devices, are not allowed. For all Scheme programming problems use recursion and functional operations. No loops; no assignment (set! and its relatives). You may also assume that the data or arguments to all functions are as specified and you do not need to check for errors (e.g., don t add code to deal with non-numbers when the data is specified to be a list of integers, or nested lists if the data is supposed to be a simple list, but do handle these things if the problem specifies it). Advice You have 50 minutes, do the easy questions first, and work quickly! Total: 100 points. Question Max Points 1 14 2 10 3 3 4 12 5 15 6 15 7 15 8 16 Total 100 Score Page 1 of 8

1. [14 pts.] Suppose we enter the following top-level definitions into a Scheme interpreter. (define a 100) (define b '(100 62)) (define c 47) (define (apples a) (odd? a)) (define (pie a) (apples (- 3 a))) (define book (lambda (a) (> a c))) What is the value of each of the following expressions, given that the above definitions are in effect? If evaluating the expression produces an error, explain what is wrong. a) (cons a b) b) (cons b b) c) (append a b) d) (book 13) e) (apples 12) f) (map apples b) g) (map pie '(7 8 9)) Page 2 of 8

2. [10 pts.] For each of the following sections, draw a boxes- n-arrows diagrams as requested showing the final result after executing all of the expressions in that section. After each diagram, answer the questions about the printed representations of some of the values defined. (a) (define x (z (x y) 3)) (define y (list x (car x))) (define z (cdr (car y))) (define w (cons 5 (cdr x))) Draw the boxes and arrows diagram for x: What are the printed values of x, y, z, and w? (b) (define a (1 2 3)) (define b (append (cdr a) (cons (car a) ()))) Draw the boxes and arrows diagram for b: What is the printed values of a and b? Page 3 of 8

3. [3 pts.] Suppose we enter the following definitions: (define x 100) (define y 7) What is the value of the following expression? (let* ((x (+ x y)) (y (- x y))) (- x y)) 4. [12 pts.] Suppose we enter the following definitions: (define k 5) (define foo (lambda (n) (lambda (w) (+ k n w)))) Describe the value of each of the following expressions. If the value is something simple like an integer, just write it down. If the value is a procedure (function closure), describe the closure precisely: what is the procedure code, and what environment bindings are included in the closure? If something is wrong with the expression, describe the error. (a) (foo 3) (b) ((foo 3) 7) (c) ((foo 3) k) (d) (((foo 3) 7) 2) Page 4 of 8

5. [15 pts.] Write a Scheme function remove-odd that takes a list of integers as an argument and returns the same list with all of the odd numbers removed. Examples: (remove-odd '(-10 6 5 0 5-3 21 68)) => (-10 6 0 68) (remove-odd '(100)) => (100) (remove-odd '()) => () Page 5 of 8

6. [15 pts.] Write a Scheme function findmax that takes a list of integers as an argument and returns the largest value in the list. It should return false if given the empty list. You may find it useful to write a helper function. Examples: (findmax '(-10 6 25 0 105-3 21 68)) => 105 (findmax '()) => #f (findmax '(10 600 25-5 -3 21 77)) => 600 Page 6 of 8

7. [15 pts.] Write a Scheme function count that takes two arguments, an integer and list of integers, and counts how many occurrences there are of the integer in the list. The list could be the null list or a nested list. If it is a nested list you must recursively count the number of occurrences in all sub-lists. (Hint: the pair? predicate can be used to test whether something is a non-empty list.) Use = to test for equality of integers. For example: (count 4 '(6 8 4 3 45 4)) => 2 (count 5 '((5 (5 4) 4) (3))) => 2 (count 4 '()) => 0 (count 4 '(3 ((43 4)) (4) (6 9 10 4))) => 3 Page 7 of 8

8. [16 pts.] Consider the following C program (which compiles and runs without errors): #include <stdio.h> void mystery(int* x, int* y, int z) { int *s = x; *x = z + 17; z = *y - 2; /* (a) draw picture at this point */ printf("in mystery: *x=%d, *y=%d, z=%d, *s=%d\n", *x, *y, z, *s); } void curious(int* x) { int b; b = 500; printf("in curious, before mystery: *x=%d, b=%d\n", *x, b); mystery(&b, x, b); printf("in curious, after mystery: *x=%d, b=%d\n", *x, b); } int main() { int x; x = 10; curious(&x); printf("in main: x=%d\n", x); return 0; } (a) Draw a diagram with boxes for each active function showing the situation right when execution reaches the printf statement in function mystery. Be sure to show the values of all of the variables in each active function. If a variable is a pointer to another variable, indicate its value by drawing an arrow between the variable name and the storage location (variable) that it points to. (b) What output is produced when this program is executed? If an address is printed out, please make up an address and label the appropriate box in your picture above with that address. (Don t worry about writing out the exact details of each message, but we should be able to tell which values you are printing where.) Page 8 of 8