Directions: Use your own paper for answers. When you are done you may keep this exam sheet and should pick up an answer sheet.
%!PS-Adobe-2.0
/r 100 def
/wedge {
newpath
0 0 moveto
r -15 sin r mul lineto
r 0 15 sin r mul -90 90 arc
closepath
} def
/pie {
1 1 12 {
12 div setgray
gsave wedge
gsave fill grestore
0 setgray stroke
grestore
30 rotate
} for
} def
3 setlinewidth
pie
showpage
This program prints the picture shown on the right centered at the (0, 0) coordinate of the page, so that 3/4 of the picture is off the page.
x y r ang1 ang2 arc % append counter-clockwise arc, center (x,y), radius r, % from angle ang1 to ang2; stack empty afterward.)
P ----> E #
E ----> E + E
E ----> E * E
E ----> ( E ) | a | b | c
n = 1;
WHILE (10 - n) {
WRITE(n);
WRITEC(32); /* a blank */
n = n + 1;
}
WRITEC(10); /* a newline */
whilestmt ----> "WHILE" "(" expr ")" stmt
reigns(henry7, 1485, 1509). reigns(henry8, 1509, 1547). reigns(edward4, 1547, 1553). reigns(jane_grey, 1553, 1553). reigns(mary1, 1553, 1558). reigns(elizabeth1, 1558, 1603). reigns(james1, 1603, 1625). reigns(charles1, 1625, 1642). reigns(oliver_cromwell, 1642, 1658). reigns(richard_cromwell, 1658, 1659). reigns(charles2, 1660, 1685). reigns(james2, 1685, 1688). reigns(mary2, 1688, 1694). reigns(william3, 1688, 1702). reigns(anne, 1702, 1714). reigns(george1, 1714, 1724). reigns(george2, 1727, 1760). reigns(george3, 1760, 1811). reigns(george4, 1811, 1830). reigns(william4, 1830, 1837). reigns(victoria, 1837, 1901). reigns(edward7, 1901, 1910). reigns(george5, 1910, 1936). reigns(edward8, 1936, 1936). reigns(george6, 1936, 1952). reigns(elizabeth2, 1952, 2001). house_of(henry7, tudor). house_of(henry8, tudor). house_of(edward4, tudor). house_of(jane_grey, tudor). house_of(mary1, tudor). house_of(elizabeth1, tudor). house_of(james1, stuart). house_of(charles1, stuart). house_of(oliver_cromwell, commonwealth). house_of(richard_cromwell, commonwealth). house_of(charles2, stuart). house_of(james2, stuart). house_of(mary2, orange). house_of(william3, orange). house_of(anne, stuart). house_of(george1, brunswick). house_of(george2, brunswick). house_of(george3, brunswick). house_of(george4, brunswick). house_of(william4, brunswick). house_of(victoria, brunswick). house_of(edward7, saxe_coburg_gotha). house_of(george5, windsor). house_of(edward8, windsor). house_of(george6, windsor). house_of(elizabeth2, windsor). ruler(N, Y) :- reigns(N, A, B), Y >= A, Y =< B. /* =< instead of <= */
ten42% pl ?- consult(rulers). rulers compiled, 0.00 sec, 5,164 bytes. Yes ?- ruler(X, 1560). X = elizabeth1 ; No ?- ruler(X, 1688). X = james2 ; X = mary2 ; X = william3 ; No ?- house_of(X, stuart). X = james1 ; X = charles1 ; X = charles2 ; X = james2 ; X = anne ; NoExplain why there are the three answers to ruler(X, 1688).