bbw(1) :- write(' One bottle of beer on the
wall').
bbw(N) :- write(N), bob, write(' on the
wall').
bb(1) :- bbw(1), write(', one bottle of beer'),
tod,
write(' No'), bob, write('.').
bb(N) :- bbw(N), write(', '), write(N), bob,
tod,
M is N - 1, bbw(M), write('.\n'), bb(M).
bob :- write(' bottles of beer').
tod :- write('. Take one down; pass it around -
').