cs173: Programming Languages

Similar documents
cs173: Programming Languages Final Exam

cs173: Programming Languages Midterm Exam

cs173: Programming Languages

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

CS143 Final Spring 2016

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

CS 1101 Exam 3 A-Term 2013

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

CS143 Final Fall 2009

Implementing Continuations

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CPSC 311, 2010W1 Midterm Exam #2

An Introduction to Functions

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

YOUR NAME PLEASE: *** SOLUTIONS ***

CSE505, Fall 2012, Midterm Examination October 30, 2012

Structure and Interpretation of Computer Programs

CS115 - Module 10 - General Trees

Exam 2. Name: UVa ID:

Structure and Interpretation of Computer Programs

Project 5 - The Meta-Circular Evaluator

CSE341 Spring 2017, Final Examination June 8, 2017

Repetition Through Recursion

CS 1102, A05 Final Exam

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

CSE341 Spring 2017, Final Examination June 8, 2017

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

CS558 Programming Languages

Qualifying Exam in Programming Languages and Compilers

Heap Management. Heap Allocation

Introduction to OO Concepts

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

CS558 Programming Languages

Functional Programming. Big Picture. Design of Programming Languages

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

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 19 November 2014

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

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

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly)

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

CS 2505 Computer Organization I

CS 314 Principles of Programming Languages. Lecture 16

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

Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

UNIVERSITY REGULATIONS

University of Virginia Department of Computer Science. CS 4501: Information Retrieval Fall 2015

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Principles of Algorithm Design

Random Testing in 321

Structure and Interpretation of Computer Programs

CMSC 331 Final Exam Section 0201 December 18, 2000

Module 10: General trees

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

Type Inference: Constraint Generation

COSE212: Programming Languages. Lecture 0 Course Overview

Structure and Interpretation of Computer Programs

ECE264 Fall 2013 Exam 3, November 20, 2013

Box-and-arrow Diagrams

Freeing memory is a pain. Need to decide on a protocol (who frees what?) Pollutes interfaces Errors hard to track down

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.

CS558 Programming Languages

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

G Programming Languages - Fall 2012

cs1120: Exam 2 Due: Thursday Nov 29 at 3:30pm (in class)

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

Chapter 6 Introduction to Defining Classes

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

CS2500 Exam 2 Fall 2011

Cs445 Homework #1. Due 9/9/ :59 pm DRAFT

Concepts of program design Exam January 31, 13:30 16:30


Structure and Interpretation of Computer Programs Summer 2014 Midterm 1

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

Structure and Interpretation of Computer Programs

Midterm Exam (REGULAR SECTION)

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division DO NOT. P. N.

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

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

CS 3114 Data Structures and Algorithms READ THIS NOW!

CS558 Programming Languages

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

EECS 481 Software Engineering Exam #1. You have 1 hour and 20 minutes to work on the exam.

Midterm II CS164, Spring 2006

such a manner that we are able to understand, grasp and grapple with the problem at hand in a more organized fashion.

COMPUTER SCIENCE TRIPOS

EECS 395 Programming Languages

Final Examination CS 111, Fall 2016 UCLA. Name:

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 19, 2014

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

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

CSE351 Winter 2016, Final Examination March 16, 2016

Racket Style Guide Fall 2017

UMBC CMSC 331 Final Exam

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

CSE341 Autumn 2017, Final Examination December 12, 2017

Transcription:

cs173: Programming Languages Final Exam Fall 2001 Please read all the instructions before you turn the page. This exam is worth 101 points. We will assign partial credit to partial responses, provided we can decipher the response, it reflects a correct understanding of course material, and does not violate the requirements of the problem. Exam rules: ffl Your responses to this exam are due by 1200hrs on 2001-12-15 (Saturday). We will post turn-in instructions on the course newsgroup. ffl If you believe a question is underspecified or buggy, make a reasonable assumption, and document your claim and your work-around. (However, we believe none of the questions fall in this category. Therefore, you should invoke this right rarely or never don t turn in blow-by-blow thoughts on every response!) ffl The exam is open book with respect to the course notes for the year 2001 (including Wilson s monograph, notes provided by guest lecturers, and newsgroup postings). You may not refer to any other sources related to the course between the time you start and finish the exam. ffl You have three hours and 15 minutes to take this exam. Time begins when you start reading the exam questions. The first three hours must be a single, contiguous block. At some point, either immediately or later (but before the responses are due), you may use an additional 15 contiguous minutes to change or augment your answers. ffl All Scheme code responses must use the dialect employed in this course. You may not use assignments or continuations unless expressly permitted to do so in the problem statement. ffl Put your name on every single page you turn in. ffl Solutions may be hand-written, but the burden of legibility rests on you. ffl Unless you are typesetting your entire solution, please fill your answers in a print-out of the exam itself. As much as possible, use the spaces provided for each response. If you use an overflow sheet, number it carefully and indicate its use in the main exam. Staple all sheets together. If you fail to perform any of these steps, we may simply overlook parts of your response. ffl You may evaluate any of the programs related to this exam on a computer. ffl You must neither give assistance to any other course participant, nor receive assistance from anyone other than the course staff, on material under examination. Brown University has an Academic Code that governs this exam and all our other transactions. I expect you, as students and scholars, to abide by it faithfully and fully. Problem Max Score 1 15 2 5 3 20 4 15 5 20 6 5 7 20 8 1 Total 101 1

Problem 1: CPS [15 point(s)] CPS the following function: (define (fold f l acc) (cond [(empty? l) acc] [(cons? l) (fold f (rest l) (f (first l) acc))])) You need not convert the list primitives (empty?, rest, etc). You should assume that the first argument to fold has itself been converted into CPS (and may not be primitive). Convert into CPS the following use of fold so that it uses the CPS-converted version above: (fold + (list 1234) 0) ;; this evaluates to 1 + 2 + 3 + 4 = 10 2

Problem 2: Overloading [5 point(s)] Many scripting languages include a feature they call polymorphism, but is technically known as overloading. In this feature, one operator name serves as a front for several different, unrelated operators; the language picks the right operator based on the types of arguments given at run-time. For instance, + implements addition when given numbers, concatenation (string-appending) when given strings, list appending when given lists, and so forth. Why is overloading different from polymorphism (as we ve studied it in this class), even though it superficially seems similar? 3

Problem 3: Type Inference [20 point(s)] Consider the following typed Rip expression: fproc ff : 2 1 g : 2 2 fproc fx : 2 3 g : 2 4 fproc fy : 2 5 g : 2 6 fcons x ff ff ygggggg We have left the types unspecified (2 n ) to be filled in by the type inference process. Derive type constraints from the above program. Then solve these constraints. From these solutions, fill in the values of the boxes. Be sure to show all the steps specified by the algorithms (i.e., writing the answer based on intuition or knowledge is insufficient). You should use type variables where necessary. To save writing, you can annotate each expression with an appropriate type variable, and present the rest of the algorithm in terms of these type variables alone (to avoid having to copy the corresponding expressions). If you do this, be sure to annotate every sub-expression with a type variable. Be sure the annotations are clearly readable! 4

Problem 4: Memory Management and Type Soundness [15 point(s)] We ve said, in class, that the existence of some pointer-oriented operations in languages like C and C++ make it impossible to prove a type soundness theorem for those languages. What primitive(s) cause(s) a problem, and what is that problem? For a language like Scheme, ML or Java, is garbage collection necessary to establish type soundness? Why or why not? 5

Problem 5: Generational Garbage Collection [20 point(s)] A generational garbage collector naturally tracks references from newer objects (ones allocated more recently) to older ones. A major challenge is keeping track of references that go the other way: from old objects to new. What in the design of a copying generational collector makes it natural for the collector to track references from new to old, rather than vice versa? Distinguish between variable mutation and value mutation. In variable mutation, we change the value held by a variable itself. In value mutation, the variable still refers to the same object; it s the content of the object that changes. (For example, set! in Scheme implements variable mutation, while vector-set! implements value mutation.) Which of these does a generational collector need to track specially? For each one, state whether it is or isn t tracked, with a brief justification for why or why not. There is one fundamental property (as opposed to a mere implementation detail) common to page-marking, wordmarking and card-marking that store lists do not share. What is this? 6

Problem 6: Conservative Garbage Collection [5 point(s)] Why does a conservative garbage collector employ a mark-and-sweep strategy (which is generally less efficient than advanced copying strategies)? You may find many reasons, but state the one that is clearly the most important. 7

Problem 7: Stack Walking [20 point(s)] Some applications share information between their sub-systems by placing marks on the executing program s stack. Java s security manager functions this way, as does the Stepper in DrScheme. The following two Rip expressions represent a very simple version of these operations: ffl fmark hrpi hrpig evaluates the first sub-expression, places its value on the stack as a mark, then evaluates its body, which is the second sub-expression. When the body finishes evaluating, the mark disappears from the stack. The value of the entire expression is the value of the body. ffl fmost-recent-markg walks the stack from newest-to-oldest frames, until it finds a mark, and returns this mark as its value. Using the CPSed interpreter on the next page as your starting point, implement these two operations. (To make the problem simpler, we ve removed procedures, variables and applications from the language, leaving only arithmetic.) Assume the programmer never writes an ill-formed mark query, i.e., all fmost-recent-markg requests lie within enclosing mark expressions. Here are some examples of program behavior: 3g =) 3 fmark f+ 34g f+ 56gg =) 11 fmark f+ 34g fmost-recent-markgg =) 7 fmark 5 fmost-recent-markggg =) 5 fmark fmost-recent-markg 3gg =) 3 fmark fmost-recent-markg fmost-recent-markggg =) 4 f+ fmark 5 fmost-recent-markgg fmark 6 fmost-recent-markgggg =) 11 f+ fmark 10 1g fmost-recent-markggg =) 5 Hint: Previously, a continuation responded to only one kind of message : consume a value, and perform the rest of the computation. Now, a continuation may want to respond to two different kinds of messages... 8

;; An RP is one of (define-struct nume (num)) (define-struct adde (lhs rhs)) ;; num : number ;; lhs : RP, rhs : RP (define (interp/k expr k) (cond [(nume? expr)(k expr)] [(adde? expr)(interp/k (adde-lhs expr) (lambda (lhs-v) (interp/k (adde-rhs expr) (lambda (rhs-v) (k (nume+ lhs-v rhs-v))))))] [else (error interp "not a valid expression" expr)])) (define (run expr) (interp/k expr (lambda (x) x))) 9

Problem 8: Bonus Question [1 point(s)] What programming language would Thomas Jefferson have used? 10