Corrections, FAQs, and Hints for Assignment 9

CSc 372, Fall 2006

Last Update: December 4, 2006, 12:11am


Corrections

 

1.         The write-up for pipes.pl does not show the done command. It causes the pipes interpreter to exit and succeed:

 

    ?- pipes.

 

    Command? done.

 

    Yes


            done should also be shown by info:

 

Command? info.

...

info -- print this message

done -- exit

 

Command?

 

2.         The write-up for buy.pl refers to the Ant Farm as farm in one place and antfarm in another. a9/buyfacts.pl had the same error. It should be antfarm in both places. buyfacts.pl has been corrected.


FAQs on pipes (see correction #1 above, too!)

 

Q1:      I'm having trouble with the echo fact in pipes.pl. One error I'm getting is this:

 

    ERROR: Undefined procedure: echo/0

 

A:        As the first line in pipes.pl, add this:

 

    :-dynamic(echo/0).

 

Q2:     I'm having trouble understanding the interaction of the echo command and prompting. Can you say some more about that?

 

A:        Here's a Ruby analog that may help:

 

if not echo_mode

    print "Command? "

end

 

cmd = gets

 

if echo_mode

    printf("Command: %s\n", cmd)

end

 

Q3:     When I type a command like weld(a,b). at the pipes Command? prompt it looks OK for a moment but then the cursor jumps to the start of the line and overwrites part of it. In the end it looks like this:

 

weld(a,b).eld(a,b)

A:        This is a miserable problem that crops up in the Linux version but not in the Windows version—that's why I didn't notice it when developing my solution. At present, aside from simply ignoring the botched echo the only workaround I've got is to hit ENTER at the Command? prompt, which then takes you to Prolog's |: prompt, where the echo is handled properly.

 

Q4:     Does it matter whether pipes leaves echo on or off?

A:        Don't worry about that. We'll only do one pipes run per Prolog invocation.


Assorted FAQs

 

Q1:     What's the right way to include the facts in a9/buyfacts.pl in my buy.pl AND not get diffs from tester?

A:        Make the following the first line in your buy.pl:

 

:- ['/home/cs372/fall06/a9/buyfacts'].

 

Q2:     How does listsum respond to a request for an alternative (via a semicolon)?

A:        It fails—there are no alternative answers.

 

Q3:     Can helper predicates be used in pw.pl?

A:        Yes! Of course, the helpers must obey the restrictions, too. If you think about it, I could have prohibited the use of append but you could work around that by writing your own append—it doesn't use anything but list construction (see slide 111). Likewise, if you're dying for =/2, just write a replacement: u(X,X). In contrast, one thing you really can't do without is atom_chars.

 

Q4:     In connect.pl, do I have to use all the cables and/or does the length have to be exact?

A:        "No" on both. Any sequence of cables that is at least long enough to reach and is properly mated is a correct answer. UNLIKE the brick laying examples, you don't need to use all the cables and the length doesn't need to be exact. (If you look closely at the examples you'll find examples of both excess length and leftover cables.)

 

Q5:     In buy.pl does it matter in which order the prohibited items are printed?

A:        No, don't worry about the ordering. (The tester script uses a Ruby program to put them in alphabetical order for output.)



Typos

 

1.         The first sentence in the write-up for pw.pl should be "In this problem you [are] to write..."