CSC 8310 -- Final Exam
Section 001: Tuesday & Thursday 4:30 to 5:45pm in Mendel G30
Section 002: Thursday 6:15 to 8:45 in Mendel G30
Spring 2000, Villanova University
Name: _________________________________
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<unary> ::= + | -
<binary> ::= * | /
<expr> ::= <digit> | <unary> <expr> | <expr> <expr> <binary>
(4 points) Which of the following things are valid <expr>s? Write
"yes" for each valid <expr>, "no" for each
expression that is not a <expr>.
2 + 3 *
+ 2 3 *
2 3 / - 4 /
- 2 3 4 / / (2 points) Write a valid <expr> that is exactly seven symbols long.
f(x, y) = g(5, 7)mother(John, dick) = mother(jack, Richard)mother(Tom, dick) = mother(dick, Harry)me = grandpaw(me, Myself)son(X, Y). /* X is the son of Y. */
daughter(X, Y). /* X is the daughter of Y. */
parent(X, Y). /* X is a parent of Y. */
Write Prolog rules (exactly one each) for:
mother(X, Y). /* X is the mother of Y. */
grandmother(X, Y). /* X is the mother of a parent of Y. */
sibling(X, Y). /* X and Y have the same mother and the same father. */
(car '(a (b (c))))(car '(((a) b) c))(car '(()))(cdr '(a b c))(cdr '((a b) (c d)))(cdr '(()))(cons 'a '((b) c))(cons '(a b) '(c d))(cons '() '())(eq nil ())(eq '(a b) '(a b))(cond ((cons 'a 'b) 'a) (t 'b) )(null (null ()))(cons (car '(a b c)) (cdr '(b a c)))(append (list 'a) '(list b c))cond expression that is equivalent to, but simpler than, (cond ((atom a) x) ((null a) x) (t y))take 5 [2, 3..]
filter even [1..10]
[x | x <- [1..5]]
[(x,y) | x <- [1, 2], y <- [1..2]]
break (== 'c') "abracadabra"
map f [1..5] where f = (3 -)
2 : "abc"
f [1..3] where f x@(y:z) = (x, y, z)
(x `mod` y) means the same as (mod x y) last has the same type as init. x is a variable, (x) has the same type as x.:: in Haskell?
ilist of integers,
returns a new list containing the nonnegative integers of ilist.