| CSC 1800 Midterm Exam David Matuszek, Fall 2000 Villanova University |
Name_____________________________________ |
Part I -- Prolog
loves(John, Mary) = loves(Mary, Bill)
2 + 3 = 3 + 2brother(john, X) = sister(Y, mary)mother(john, spouse(X)) = mother(X, Y)\+ (father(X, Y) = father(john, bill))[X | Y] = [1, 2, 3]
describe(meadow) :- write("You are in a beautiful sunlit
meadow."). mortal(X) :- man (X).take(X) :- heavy(X), write('You can't lift that!'), !, fail.Happy(X) :- healthy(X), wealthy(X), wise(X).error(X) :- write('Error: '), write(X). nl. male(tom).
male(dick).
female(mary).
female(jane).
mother(mary, tom). /* Mary is the mother of John */
mother(mary, dick).
mother(mary, jane).
Further assume that people with the same mother also have the same father,
that is, you don't have to worry about half-sisters or half-brothers. daughter(X,Y) to decide whether
X is the daughter of Y. sibling(X,Y) to decide whether
X and Y are siblings (have the same parents). Be careful
to ensure than no one is his/her own sibling. (Hint: use two clauses.)
brother(X,Y) to decide whether
X and Y are brothers. You can use sibling(X,Y)
if you like.Part II -- Smalltalk
Transcript
window)? myArray in the Transcript
window. Do not include spaces or newlines in the output. (Hint: avoid
indexing the array.) Person object in Smalltalk
that has a name instance variable. name. name.
Part III -- General
|
|
int n subrange 1..10 declares an integer named
n with allowable values 1 through 10. Briefly name two possible reasons
for having such a construct in the language. && and
|| operators in Java are actually control structures. Why? <letter> and <digit>
are defined in the usual way. The following BNF defines a <name>.
Give a precise English language definition of <name>. Do
not use examples.
<alphanum> ::= <letter> | <digit>
<name> ::= <letter> | <letter> <alphanum> | <letter> _ <alphanum>