DOC PREVIEW
UMD CMSC 330 - Example Quiz #2

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC330 Fall 2009 Example Quiz #2 Name Discussion Time (circle one): 10am 11am 12pm 1pm 2pm 3pm Do not start this exam until you are told to do so! Instructions • You have 25 minutes for this quiz. • This is a closed book exam. No notes or other aids are allowed. • Answer essay questions concisely using 2-3 sentences. Longer answers are not necessary and a penalty may be applied. • For partial credit, show all of your work and clearly indicate your answers. • Write neatly. Credit cannot be given for illegible answers. 1. (16 pts) OCaml Types and Type Inference a. (2 pts each) Give the type of the following OCaml expressions i. [ (“1”, 2) ; (“3”, 4) ] Type = ii. fun f a -> [a ; a+1] Type = b. (3 pts each) Write an OCaml expression with the following type i. int * int list Code = ii. int list -> (int -> int) Code = c. (3 pts each) Give the value of the following OCaml expressions. If an error exists, describe the error. i. [1;2]::[3] Value = ii. let x y = y 3 in x (fun z -> z – 1) Value =2. (18 pts) OCaml Programming Solve the following OCaml programming problems. You are allowed to use List.rev (reverses a list) and the following (curried) map and fold functions, but no other OCaml library functions. Your solution must run in O(n) time for input lists of length n. a. (9 pts) Write a function makeLists which when applied to a list lst, creates a new list for every element of lst, returning the results in a single list. You may use map or fold if you wish, but it is not required. Example: makeLists [1;2;4] = [[1];[2];[4]] b. (9 pts) Using either map or fold and an anonymous function, write a function over20 which when applied to a list of ints lst, returns a list of all elements of lst that are 21 or over (preserving their relative order in lst). Example: over20 [33;18;21;19] = [33;21] let rec map f l = match l with [] -> [] | (h::t) -> (f h)::(map f t) ;; let rec fold f a l = match l with [] -> a | (h::t) -> fold f (f a h) t ;;3. (18 pts) Parsing Consider the following grammar: S → aA | A A → bS | ca a. (6 pts) Compute First sets for S and A b. (12 pts) Write a predictive, recursive descent parser for the


View Full Document

UMD CMSC 330 - Example Quiz #2

Documents in this Course
Exam #1

Exam #1

6 pages

Quiz #1

Quiz #1

2 pages

Midterm 2

Midterm 2

12 pages

Exam #2

Exam #2

7 pages

Ocaml

Ocaml

7 pages

Parsing

Parsing

38 pages

Threads

Threads

12 pages

Ruby

Ruby

7 pages

Quiz #3

Quiz #3

2 pages

Threads

Threads

7 pages

Quiz #4

Quiz #4

2 pages

Exam #2

Exam #2

6 pages

Exam #1

Exam #1

6 pages

Threads

Threads

34 pages

Quiz #4

Quiz #4

2 pages

Threads

Threads

26 pages

Exam #2

Exam #2

9 pages

Exam #2

Exam #2

6 pages

Load more
Download Example Quiz #2
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 Example Quiz #2 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 Example Quiz #2 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?