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
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<unary> ::= + | -
<binary> ::= * | /
<unit> ::= <digit> | <unit> <unary> | <unit> <binary> <unit>
(4 points) Which of the following things are valid <unit>s? Write
"yes" for each valid <unit>, "no" for each
expression that is not a <unit>.
2 * 3 - * 4
2 3 + 4 -
1 - / 2 + / 3
2 - * 3 / 4 + / 5 (2 points) Write a valid unit that is exactly eight symbols long.
f(X, Y) = g(5, 7)mother(john, Dick) = mother(Jack, richard)mother(tom, Dick) = mother(Dick, harry)Me = grandpaw(Me, myself)male(X). /* X is a male. */
female(X). /* X is a female. */
child(X, Y). /* X is a child of Y. */
Write Prolog rules (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 father. */
(car '(a b c))(car '((a b) (c d)))(car '(()))(cdr '(a b c))(cdr '((a b) (c d))(cdr '(()))(cons 'x '(a b c))(cons '(a b) '(c d))(cons '() '())(eq 'a 'A)(eq '(a b) '(a b))(cond ((cdr '(a)) 1) (t 2) )(null nil)(cons (car '(a b c)) (cdr '(a b c))(list (car '(a b c)) (cdr '(a b c)))COND is not a function but a "special form."
What does this mean?length "hello"
take 5 [2, 3..]
map even [1..10]
filter even [1..10]
init [1..5]
[x | x <- [1..5]]
[x | x <- [1..5], even x]
[(x,y) | x <- [1, 2], y <- [1..2]]
init "curry"
break (== 'c') "abracadabra"
break (== 'c') "abracadabra"
map f [1..5] where f = (3 -)
:type even
2 : "abc"
take 5 (iterate (2 *) 1)
f [1..3] where f x@(y:z) = (x, y, z)
Please sign and date: I promise not to discuss the contents of this exam with
anyone until after the end of the semester.
Signed ___________________ Date __________