Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Prolog

(ISO Prolog w/ red cuts)

Date:04/12/06
Author:Brent Spillner
URL:n/a
Comments:1
Info:n/a
Score: (2.96 in 27 votes)
% 99 bottles of beer song implemented in Prolog
% Released into the public domain in 2006 by Brent Spillner

wall_capacity(99).

wait(_) :- true.

report_bottles(0) :- write('no more bottles of beer'), !.
report_bottles(X) :- write(X), write(' bottle'),
                     (X = 1 -> true ; write('s')),
                     write(' of beer').

report_wall(0, FirstLine) :-
                  (FirstLine = true -> write('No ') ; write('no ')),
                  report_bottles('more'), write(' on the wall'), !.
report_wall(X, _) :- report_bottles(X), write(' on the wall').

sing_verse(0) :- !, report_wall('No more', true), write(', '),
                 report_bottles('no more'), write('.'),
                 nl, write('Go to the store and buy some more, '),
                 wall_capacity(NewBottles), report_wall(NewBottles, false),
                 write('.'), nl.

sing_verse(X) :- report_wall(X, true), write(', '),
                 report_bottles(X), write('.'), nl,
                 write('Take one down and pass it around, '),
                 Y is X - 1, report_wall(Y, false), write('.'), nl, nl,
                 wait(5), sing_verse(Y).

:- wall_capacity(Bottles), sing_verse(Bottles).

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Tweaked Remkos versionM@11/28/052
iso, using DCGnone04/28/110

Comments

>>  Simon Brooke said on 12/20/07 18:07:48

Simon Brooke Verified works correctly with SWI Prolog 5.6.14; probably works with other Edinburgh-style Prologs.

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: