Unformatted text preview: (x,y)::t -> if k = 1 then y else (findKth (k-1) t) b. (8 pts) Using either map or fold and an anonymous function, write a curried function findGreaterThan which when given a number n and a list of ints lst, returns a list of all elements of lst greater than n (maintaining their relative ordering). You may assume (x > y) returns true when x is larger than y. Example: findGreaterThan 20 [33;18;21;19] = [33;21] findGreaterThan 65 [33;18;21;19] = let findGreaterThan v lst = List.rev (fold (fun a h -> if (h > v) then (h::a) else a) lst) 3. (6 pts) Context Free Grammars Consider the following grammar: S & E+E | E*E E & 0 | 1 | n | (S) a. (2 pts) What is the set of strings accepted by this grammar? Arithmetic expressions involving + and *. b. (4 pts) Provide a leftmost derivation of the string “(n+1)*n” for this grammar. S & E*E & (S)*E & (E+E)*E & (n+E)*E & (n+1)*E & (n+1)*n...
View Full Document
- Fall '08
- Functional Programming, pts, 2 pts, Context-free grammar, findGreaterThan