Corrections, FAQs, and Hints for Assignment 8

CSc 372, Fall 2006

Last Update: November 14, 2006, 2:16pm


IMPORTANT NOTE ABOUT op/3 in iz.pl:


             The write-up shows the code below as an example of using op/3 to make iz an operator:

 

% cat /home/cs372/fall06/a8/iz0.pl

iz(A, A) :- atom(A).

iz(R, E1+E2) :- iz(R1,E1), iz(R2,E2), concat_atom([R1,R2],R).

 

:-op(700, xfx, iz).

 

Here's the IMPORTANT part: That op call should precede the clauses for iz. The above happens to work but only because the iz rules don't use iz as an operator. Here's an improved version of the code. Note that the op call is first and that iz is used as an operator.

 

% cat /home/cs372/fall06/a8/iz1.pl

:-op(700, xfx, iz).

 

iz(A,A) :- atom(A).

iz(R,E1+E2) :- R1 iz E1, R2 iz E2, concat_atom([R1,R2],R).


FAQs

 

Q1:      Does splits really require findall, length, and member? Isn't append enough?

A:        Yes, append is enough. My excuse is that I originally had splits returning a list of lists and when I switched to a generative form I failed to rethink the problem.

 

Q2:      What is the behavior of ?- splits([1],L).?

A:        It fails.


Typos

 

1.         The comment in the first query on page 6 should read % No space between + and -