CPSC 312 2017 - Midterm #2 - Variant #A (you can tell which variant you did from question 1) Question 1 (a) Foo Inc published a book "Prolog is Fun Book" Foo Inc is a publisher. (b) The most important part is you need to create a new individual. prop(cs3121012017,course,cs312). prop(cs3121012017,section,101). prop(cs3121012017,year,2017). prop(cs3121012017,final_month,december). prop(cs3121012017,final_day,20). (a) A URI is a constant that has a well-defined and standard meaning. It is useful because everyone who uses the constant means the same thing. (It does not imply that there is a unique URI for each thing (the unique names assumption); there can be multiple URIs for the same thing.) Question 2 (a) Does not unify as I cannot be both prolog and [twists,minds] (b) {A / h(b, Z), B / b, Y / f(h(b, Z))} (c) {A / [c, s, i, s, f, u, n], B / [f, u, n], C / [i, s, f, u, n]} Question 3 yes(R,I,C) :- mp([next,to, brazil],R,I,C,[]). yes(R,I,C) :- reln([next,to,brazil],L11,I,O12,C,C12), noun(L11,R,O12,C12,[]). yes(R,I,[next_to(I,O12)|C12]) :- noun([brazil],R,O12,C12,[]). yes([],I,[next_to(I,brazil)]) :- country(brazil). yes([],I,[next_to(I,brazil)]) :-. Answer is R=[], C=[next_to(I,brazil)] Question 4 % Tree to list (with append) to_list(leaf,[]). to_list(node(LT,Root,RT),L):- to_list(LT,L0), to_list(RT,L1), append(L0,[Root|L1],L). % Tree to list (without append, using difference lists) to_list_dl(T,L) :- tree_to_list(T,L,[]). tree_to_list(leaf, L, L). tree_to_list(node(LT,Root,RT),L0,L2):- tree_to_list(LT,L0,[Root|L1]), tree_to_list(RT,L1,L2). Question 5 3rd clause should combine different list in other order Old: revFlat([[A|B]|T],R0,R2) :- revFlat([A|B],R0,R1), revFlat(T,R1,R2). Should be: revFlat([[A|B]|T],R0,R2) :- revFlat([A|B],R1,R2), revFlat(T,R0,R1). Note that just changing the order of the clauses in the body does not help!