Language:EN
Pages: 6
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
return type and the number and types its arguments

Return type and the number and types its arguments

UMBC CMSC 331 Final Examination, 16 December, 2004
UMBC CMSC 331 Final Exam
Name:______________________________ UMBC Username:__________________________ You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy or simply wrong.

1.General multiple-choice questions (30)

1 / 30
2 / 30
3 / 50
4 / 5
5 / 15
6 / 15
7 /20
8 /20
9 / 15
total / 200

1.4 The Unix YACC program parses input using a (a) recursive descent parser; (b) a top-down parser; (c) an RR(1) parser; (d) a bottom-up shift reduce parser. (D)

1.5 The main difference between a sentence and a sentential form is (a) there is no difference; (b) a sentence contains only terminal symbols but a sentential form can contain some non-terminal symbols; (c) sentential forms are a subset of sentences but the converse is not true; (d) sentential forms have no handles but a sentence does. (B)

1.10 LISP macros are primarily used to define: (a) dynamically scoped environments; (b) closures; (c) functions that don’t evaluate all of their arguments; (d) reflective programs. (C)

1

(b) S → ε | ab | ba | aSb | bSa
Stings with a prefix consisting of some number of a’s and b’s in any order followed by a postfix formed by reversing the prefix and changing each a to a b and each b to an a. The grammar is ambiguous, since there are two ways to derive the sentence “ab”: S(s,b) and S(a,S(e),b).

(c) S → aSb | C C → ε | c | Cc
Strings consisting of N a’s (N≥0) followed by any number of c’s followed by N b’s. The grammar is ambiguous since there are two ways to derive the sentence “cc”: S(C(C(c),c)) and
S(C(C(C(e),c),c)).

[T][F]: Methods declared in an interface are automatically public. [T]

[T][F]: Overloading and overriding refer the same thing in Java [F]

[T][F]: Instance variables defined by a class are always given initial values when an instance of the class is

created. [T]

[T][F]: Static methods do not require an instance of the class; they can be accessed through the class name. [T]

2

4. Java class variables (5)

If we construct an object of type Foo, where class Foo { int x = 5; int y; Foo() { x = 2; } }, what are the values of x and y in the new object?

(cons (cons (cons ‘a nil) (cons ‘b nil)) (cons ‘c nil))

5.2 Give a LISP expression using only the LIST function that will create this list.

3

(list (list (list ‘a) b) ‘c)
symbol s-expression to return the symbol
A (car (car (car x)))
B (car (cdr (car x)))
C (car (cdr x))

((AGE 20) (MAJOR “CMSC”)(COURSES (CMSC331 CMSC311 BIOL340))

(6a) Write a function ASSOC that takes two arguments, a symbol and an ALIST, and returns the item associated with that symbol (if any) in the ALIST or NIL if there is no item associated with the symbol. E.g.:

If we just return the s-expression associated with a symbol, then getting back NIL from ASSOC would be ambiguous. Was the item not found, or was it found but the associated s-expression was NIL? For example, if AL is ((TALL T) (YOUNG NIL)(HAPPY T)) consider what would be returned by (ASSOC ‘YOUNG AL) versus (ASSOC ‘RICH AL).

4

What would be printed?
V0 (A B)
V1 (A A)
V2 ((A) (A))
V3 ((A) A)
V4 (((A) A) (A) A)

(A B C)

A B C

(A (B) ((C)))

UMBC CMSC 331 Final Examination, 16 December, 2004

8. Functional programming I (20: 10/10)

(DEFUN MAXINT (L) (MAXINT1 L 0))

(DEFUN MAXINT1 (L N)

(8b) Now write a version that uses the function reduce discussed in class and shown to the right. Hint: MAXINT should be a one liner that just calls REDUCE. Consider using the built in function MAX that takes two numbers and returns the larger.

(DEFUN MAXINT1 (L) (REDUCE L #’MAX 0))

9.4 What will the following expression return?

(MAPCAR (XYZZY (LAMBDA (X)(+ X 3)) (LAMBDA (X)(* X X))) '(1 2 3 4 5 6)) (4 7 12 19 28 39)

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Ella Keady

PageId: DOC6316611