{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz3-fall10

# quiz3-fall10 - describe the error(fun x> if(x> 0 then x...

This preview shows pages 1–2. Sign up to view the full content.

CMSC330 Fall 2010 Quiz #3 Name Discussion Time (circle one): 9am 10am 11am 12pm 1pm 2pm Instructions Do not start this test until you are told to do so! You have 15 minutes for this quiz. This is a closed book exam. No notes or other aids are allowed. Answer essay questions concisely in 2-3 sentences. Longer answers are not needed. For partial credit, show all of your work and clearly indicate your answers. Write neatly. Credit cannot be given for illegible answers. 1. (12 pts) OCaml a. (2 pts) Give the type of the following OCaml expression fun x y -> x (y+2) Type = b. (2 pts) Write an OCaml expression with the following type (bool -> int) -> int Code = c. (2 pts) Give the value of the following OCaml expression. If an error exists,

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: describe the error. (fun x -> if (x > 0) then x+1) 1 Value/Error = d. (6 pts) Using fold and an anonymous function, write a function attendance which when applied to a list lst of bools, returns the number of elements of lst that are true. Example: attendance [true; false; false; true; true] = 3 let rec fold f a l = match l with -> a | (h::t) -> fold f (f a h) t 2. (8 pts) Context free grammars a. (2 pts) Write a grammar for a x b y , where x = y+3 (i.e., exactly 3 more a’s than b’s) b. (6 pts) Consider the following grammar (where S = start symbol and terminals = [ , ] , ; , e ): S & [ A ] | epsilon A & A ; S | e i. (3 pts) Present a derivation for the string [e;[e;]] ii. (3 pts) Show the parse tree for your derivation...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern