University of Toronto - Fall 2002 Department of Computer Science

CSC 324: Principles of Programming Languages


Problem Set 4 Clarifications

As usual, most questions will be answered on the newsgroup, but important clarifications, and any corrections to the specifications, will be posted here.

November 24: People still seem to be having difficulty setting up things for question 1. Here is a fully working example: samplefamily.P, sample.P, sample.in, sample.out.

November 23: Despite this being contrary to the specifications, it's ok if your solution for delete only returns one answer for the query
?- delete(X,[a,a,b,b],L).

November 22: I remember this issue frustrating me last time I worked with XSB, and it's frustrating me again. So :- [basics]. loads basics.P, but only makes it available to the interactive prompt, and not to the predicates in the file where it's located. You actually have to use import for all this to work:
:- import append/3 from basics.
will make append available to predicates within the file where it's located (but not to the interactive prompt--go figure). If you need to import more than one predicate (you won't need to in this assignment, but you might in the project), you can provide a comma-separated list of them. The /3 indicates the arity of the predicate you're importing, 3 in the case of append since it takes 3 arguments.

November 20: For question 5 (a) (even), you may not use length or mod.

November 19: Well, I should have tested the instructions below before posting them... A student pointed out that, despite having [ps4family]. at the beginning of ps4q1.P, the relations defined there are not available. The error I made is: when you pipe a test suite into Prolog, it treats everything as a query. So in a .in file, [ps4family]. is interpreted as the query ?- [ps4family]. and the file is loaded as a side-effect of executing the query. However, in a fact base file, everything is treated as facts and rules. Now, what's a query? It's actually a Horn Clause without a head. So to load another file from within a .P file, you must write :- [ps4family]., a Horn Clause without a head, and then it will get executed. So that's the line you need at the beginning of your ps4q1.P file.

November 16: Small typo in ps4family.P: it should have read married, not maried. It is now fixed. Please continue using the correct spelling provided in the handout.

November 13: For question 1, you should assume that male, female, and parent are defined as we defined them in class, providing family information. Of course, assume married is defined. You should also assume that sibling is defined as follows:
sibling(X,Y) :- parent(P,X), parent(P,Y), \+(X=Y).
Please download the file ps4family.P, which contains the definition for sibling, and load it at the beginning of your ps4q1.P file, by placing the command [ps4family]. at the beginning. You may modify ps4family.P as much as you want to add more family data and test your code, but do not add new predicates and do not change the definition of sibling. Any helper predicates you need should of course be placed in ps4q1.P with the rest of your code. If you need any further predicates we saw in class or tutorial, you will have to include them in your ps4q1.P file.

Also, for question 1 only, don't worry if your solutions produce duplicate answers. (You can't avoid it without using the cut, which we haven't discussed yet, and which you are not allowed to use for this assignment.)