Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing semicolon stepping...

Status
Not open for further replies.

Durandal

Technical User
Apr 8, 2003
1
PH
For a piece of 1st year Computer Science Prolog coursework (as part of a sheet with loads of mini-projects), I have to write a program to print out the 'song':

99 bottles of beer on the wall,
99 bottles of beer,
you take one down and pass it around,
98 bottles of beer on the wall.

For any beer(X) where X is any number. In other words, what ever number you substitute X with, the song begins on that number and counts down.

I've done it recursively (as everything seems to have to be done in prolog). Unfortunately, the program whizzes through every single number, ending up with 0 bottles.

I want to be able to force the semicolon ; stepping through each verse of the song, so that every number can be seen.

I thought it was something like "!", but that doesn't seem to work.

Ideas?
 
Hello. I don't think this is the best answer, but can.

beer(Num, More) :- Num < 1, !, fail.
beer(Num, More) :- write(Num), write('bottles'), More = '?'.
beer(Num, More) :- Num2 is Num - 1, beer(Num2, More).

?- beer(8, More).
8bottles
More = ? ;
7bottles
More = ? ;
6bottles
More = ? .
yes

?- beer(3, More).
3bottles
More = ? ;
2bottles
More = ? ;
1bottles
More = ? ;
no
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top