Unformatted text preview:

CS 538Midterm Exam1. (1 point)(a) APL(b) Autocoder(c) Jovial(d) Scheme (and Lisp indirectly)(e) Snobol2. (a) (16 points)3. (a) (5 points)4. (a) (18 points) Let L be a list of values. Write a Scheme function (split L) that splits the v...5. (a) (8 points)CS 538Midterm ExamWednesday, April 3, 20027:15 PM — 9:15 PM1221 Computer SciencesInstructionsAnswer question #1 and any three others. (If you answer more, only the first four will count.)Point values are as indicated. Please try to make your answers neat and coherent. Remember, ifwe can’t read it, it’s wrong. Partial credit will be given, so try to put something down for eachquestion (a blank answer always gets 0 points!).1. (1 point)The MultiLisp programming languages is based upon:(a) APL(b) Autocoder(c) Jovial(d) Scheme (and Lisp indirectly)(e) Snobol2. (a) (16 points)It is often the case that subprograms are called with some arguments that are constants ratherthanvariables.Inwhatwayscantheexecutionofasubprogrambeimprovedifitisknownthata particular parameter will always be a given constant parameter? Are the improvements youpropose safe? That is, will your “improved” subprogram always compute the same result asthe original subprogram?(b) (17 points)In MultiLisp we can use pcall to specify that the function and parameters in a call are to beevaluated in parallel. Is it safe to convert every function call into a pcall? If so, explain why.If not, how can a programmer decide which calls are appropriate for conversion into pcalls?3. (a) (5 points)Scheme’s map function, called as (map function list) applies its function argument toeach element of its list argument producing a list of results. The i-th element of the outputlist is the result of applying thefunction to the i-thelement of the input list.However, the exactorder in which the function is appliedto list elements (left-to-right,right-to-left, or some other)is unspecified.Write a simple Scheme function that uses map that will expose the order in which map appliesitsfunctiontolistelements.Indicatehowtheoutputproducedbythefunctionyouprovidewillanswer our ordering question.-2-(b) (14 points)map normally applies one function to a list of parameter values. Assume we want a variant ofmap, called mapF, that applies a list of functions to a single parameter value. For example,given(define (add1 v) (+ v 1))(define (add2 v) (+ v 2))(define (add3 v) (+ v 3))the call (mapF (list add1 add2 add3) 10) produces (11 12 13).Give Scheme code that defines mapF.(c) (14 points)Now let us consider a version of map called mapFL that takes a list of functions and a list ofparameter values. That is, (mapFL FunL L) takes the first function in FunL and applies it toeach value in L, forming a list of results. This list is then appended to a list of results formed byapplying the second function in FunL to the values in L. Then the third function in FunL isapplied to L, etc., until all functions in FunL have been applied to L. For example,(mapFL (list add1 add2 add3) '(10 11 12)) produces (11 12 13 12 13 14 1314 15).Give Scheme code that defines mapFL.4. (a) (18 points)Let L be alist of values. Write a Scheme function (split L) that splits the values of L into twosublists as follows:(i) If L is null, the pair (() . ()) is returned.(ii) If L is (v1) the pair ((v1) . ()) is returned.(iii) In general, L is divided into a pair of lists containing values at odd numberedpositions and values at even numbered positions. Thus (v1 v2 v3 v4...) is splitinto ((v1 v3...).(v2 v4...))For example, (split '(a b c d e) should return ((a c e) . (b d)).(b) (15 points)Transform your Scheme version of split into a MultiLisp program by adding futureswhere appropriate. Explain why you added each future. Do not add any future that doesnot contribute significant potential concurrency.5. (a) (8 points)Whatis a current continuation? What doesthecurrentcontinuationboundtok in the followingcall do?(+ (* 2 5) (call/cc (lambda (k) (k 7))) )(b) (25 points)The following Scheme function prints an infinite sequence of integers starting at 1:(define (GenInts)(let loop ((I 1))(display I)(loop (+ I 1))))Harry Hacker decides to change GenInts into a coroutine that can be resumed when neededto produce the next integer in sequence. GenInts will return a pair: the desired integer and acontinuation that can resume the co-routine:-3-(define (GenInts)(let loop ((I 1))(call/cc (lambda (k) (cons I k)))(loop (+ I 1))))Unfortunately, Harry must have been dozing in class the day continuations were discussedbecause his code doesn’t work! What is wrong?How must GenInts be changed to correctly operate as a


View Full Document

UW-Madison COMPSCI 538 - Midterm Examination

Download Midterm Examination
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Midterm Examination and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Midterm Examination 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?