<p> Name______Computer Science 260 Fall 2005 Test 3 Closed book. Closed notes.</p><p>I. Lisp/scheme expression evaluation (20 points 3/5/3/3/3/3)</p><p>Lisp uses a prefix notation for expression evaluation. Evaluate these expressions: Be careful to show a list where a list is appropriate versus an atom. Also assume the following statement has previously been executed:</p><p>(define (ssq x y) ( + ( * x x ) (* y y ) ) )</p><p>(/ 72 8 3 2)</p><p>______</p><p>(ssq 5 6)</p><p>______</p><p>(car '(+ 6 7) )</p><p>______</p><p>(+ (* 4 5) (/ 6 2))</p><p>______</p><p>(cons 'a '(1 2 3))</p><p>______</p><p>(car (cdr (cdr '(+ (* 4 5) (/ 6 2)) ) ) )</p><p>______II. Lisp/scheme functions/recursion (10 points + 10 BONUS points) Given the following Scheme function:</p><p>(define (su S1 S2 ) ( cond ( (null s1) s2 ) ( (MEMBER (car S1) S2) (su (cdr S1) S2) ) ( else (cons (car S1) (su (cdr S1) S2) ) ) ) )</p><p> where S1 and S2 are simple lists (no sublists) and assume MEMBER is a function that takes an element and checks to see if it is in a list</p><p>Briefly describe what the function su does.</p><p>BONUS: Give an example call to the function that shows how to use the function (assuming no use of sublists) and show the output produced by your example.</p><p>CALL-></p><p>OUTPUT-> III. Concurrency ( 29 points 2/2/2/2/3/3/6/3/3/3 each ) Assume that a variable T begins with the value 3. Two parallel activities want to modify T. One wants to execute T = T * 2 and the other wants to execute T = T + 1;</p><p>List four possible outcomes (resulting values of T) which are possible if one does NOT use any synchronizing mechanisms.</p><p>------</p><p>------</p><p>------</p><p>------</p><p>What is a critical section?</p><p>Given the name of one primitive used to handle critical sections.</p><p>Give a specific application scenario where the use of these primitives to manage critical sections would be important and define the problem that could result from a lack of use of the primitive. Given the following thread class, show three possible outputs that could result from it’s execution. public class SimpleThread extends Thread { public SimpleThread(String str) { super(str); } public void run() { System.out.println("A" + getName()); System.out.println("B" + getName()); } } public class TwoThreadsDemo { public static void main (String[] args) { new SimpleThread("X").start(); new SimpleThread("Y").start(); } } OUTPUT 1 OUTPUT 2 OUTPUT 3</p><p>III. Scope Rules (16 points 6/10) Given the following program structure if a c/c++ program with three files: #include …</p><p> void main () {</p><p>}</p><p>#include …</p><p> void one () {</p><p>}</p><p>#include …</p><p> void two () {</p><p>}</p><p>Show how to properly declare two integer variables (i and k) in the main routine file and then how to make declarations for one to be able to access i and for two to be able to access k. Given the following program: program main; var x,y: integer; procedure sub1; begin {sub1} writeln('At begin of sub 1 x=',x, 'y=', y); x:=4; y:= 23 end; {sub1} procedure sub2; var x,y: integer; begin {sub2} x:=10; y:= 6; sub1; writeln('At end sub 2 x=',x, 'y=', y) end; {sub2} begin {main} x:=12; y:=14; sub2; writeln('At end of main x=',x, 'y=', y) end. {main}</p><p>Assuming the program was compiled and run with DYNAMIC scope rules, show the output printed. Don’t get caught up on syntax, just address the obvious.</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-