Mark your answers on a scantron 882-E marking sheet, not on these question sheets as only the 882-E form will be used for scoring.
On the 882-E form, in the boxes provided in the margin, be sure to write the following:
| Your full name for NAME |
| CS 152 for SUBJECT |
| M1-SPRING-2008 for TEST NO. |
At the conclusion of the exam, turn in only the 822-E marking sheet and keep these question sheets.
(car (cdr (cdr (list 1 2 3))))
A) 2
B) 3
C) (3)
D) (2 3)
E) Error, need to quote the values 1, 2, and 3
(cons 1 2)
A) (quote 1 2)
B) (cons 1 2)
C) (1 . 2)
D) (1 2)
E) Error, need to quote 1 and 2
(cons a b)
A) (quote a b)
B) (cons a b)
C) (a . b)
D) (a b)
E) There is an error, because a and b need to be quoted
(cons 1 (cons 2 3))
A) (cons 1 (cons 2 3))
B) (1 2 3)
C) (1 . 2 3)
D) (1 2 . 3)
E) Error, need to quote 1, 2, and 3
(quote a b)
A) (quote a b)
B) '(a b)
C) a b
D) (a b)
E) There is an syntax error due to wrong number of arguments
(quote (a b))
A) (quote (a b))
B) '(a b)
C) a b
D) (a b)
E) There is a syntax error due to argument structure
(cdr (quote ((3 4) (5 6))))
A) (5 6)
B) ((5 6))
C) ((3 4) (5 6))
D) ()
E) Scheme prints an error
(cdr ((3 4) (5 6)))
A) (5 6)
B) ((5 6))
C) ((3 4) (5 6))
D) ()
E) Scheme prints an error
(caadr (quote ((3 4) (5 6))))
A) 3
B) 5
C) 6
D) (5 6)
E) (6)
(cdadr (quote ((3 4) (5 6))))
A) 3
B) 5
C) 6
D) (5 6)
E) (6)
(cons '(11 22) '(33 44))
A) ((11 22) 33 44)
B) ((11 22) (33 44))
C) (11 22 (33 44))
D) (11 22 33 44)
E) Scheme reports an error
(list '(11 22) '(33 44))
A) ((11 22) 33 44)
B) ((11 22) (33 44))
C) (11 22 (33 44))
D) (11 22 33 44)
E) Scheme reports an error
(append '(11 22) '(33 44))
A) ((11 22) 33 44)
B) ((11 22) (33 44))
C) (11 22 (33 44))
D) (11 22 33 44)
E) Scheme reports an error
A) (list? ())
B) (list? cons 1 2))
C) (list? '(1 2 3))
D) All of the above
E) (A) and (C)
A) (eq? 7 7)
B) (eq? (+ 3 4) (+ 2 5))
C) (eq? '(11 22) '(11 22))
D) All of the above
E) (A) and (B)
A) (equal? 7 7)
B) (equal? (+ 3 4) (+ 2 5))
C) (equal? '(11 22) '(11 22))
D) All of the above
E) (A) and (B)
> (define (foo n)
(lambda (i)
(set! n (+ n i))
n))
> (define x (foo 100))
> (x 3)
103
> (x 10)
113
> (define y (foo 50))
>
(y 3)
A) Nothing prints
B) 113
C) 116
D) 50
E) 53
(define (bar n)
(if (null? n) n
(cons (car n) (bar (cdr n)))))
A) Always returns null, ()
B) Returns the argument list
C) Returns the reversed argument list
D) Returns the first element of the argument list
E) Returns the last element of the argument list
(define (bar n)
(define (bar-iter n result)
(if (null? n) result
(bar-iter (cdr n) (car n))))
(bar-iter n '()))
A) Always returns null, ()
B) Returns the argument list
C) Returns the reversed argument list
D) Returns the first element of the argument list
E) Returns the last element of the argument list
(define (bar n)
(define (bar-iter n result)
(if (null? n) result
(bar-iter (cdr n) (cons (car n) result))))
(bar-iter n '()))
A) Always returns null, ()
B) Returns the argument list
C) Returns the reversed argument list
D) Returns the first element of the argument list
E) Returns the last element of the argument list
interface Incrementor {
int inc (int i);
};
class Foo
static public Incrementor gen( int n ) {
return new Incrementor() {
public int inc( int i ) {
n = n + i;
return n;
}
};
}
}
A) Fails to compile because Foo is not declared "public"
B) Fails to compile because class Foo needs to be in it own separate file
C) Fails to compile and emits a message that n should be declared "final"
D) Fails to compile because Java doesn't support closures
E) (C) and (D)
A) Allocates a memory entity for a variable or object
B) Associates a name to an entity
C) Represents the rest of the computation given a particular point in the computation
D) Is an abstraction binding a function to its extent
E) None of the above
A) Allocates a memory entity for a variable or object
B) Associates a name to an entity
C) Represents the rest of the computation given a point in the computation
D) Is an abstraction binding a function to its extent
E) None of the above
A) Allocates a memory entity for a variable or object
B) Associates a name to an entity
C) Represents the rest of the computation given a point in the computation
D) Is an abstraction binding a function to its extent
E) None of the above
A) Are not supported by Java
B) Are functions that can be the return result of a procedure/function
C) Are supported by Scheme, JavaScript
D) All of the above
E) None of the above
(Note, be careful not to confuse with first class objects)
A) Are not supported by Java
B) Are definable by lambda expressions
C) Are supported by Scheme, JavaScript
D) All of the above
E) None of the above
(Note, be careful not to confuse with anonymous classes)
A) A Stack of Activation Records
B) An A-list (Association List)
C) A Hash Table
D) Closures
E) None of the Above
A) A Stack of Activation Records
B) An A-list (Association List)
C) A Hash Table
D) Closures
E) None of the Above
int x = 0;
int f () { return x; }
int g () { int x = 1; return f(); }
Consider what g() returns under two situations:
A) g() returns 0 under either of these semantics
B) g() returns 1 under either of these semantics
C) g() returns 0 using lexical scope (and dynamic extent) semantics
D) g() returns 1 using lexical scope (and dynamic extent) semantics
E) None of the above
outer = function (x) {
inner = function (y) {
x = x + y;
return x;
};
return inner;
};
afunc = outer(5);
afunc(3);
afunc(2);
The last call, afunc(2), returns 10 because JavaScript uses:
A) A-Lists
B) Continuations
C) Closures
D) Prototype inheritance
E) Private inheritance