99 Bottles of Beer/Prolog: Difference between revisions

m
Fixed syntax highlighting and duplicate headers.
m (Fixed syntax highlighting and duplicate headers.)
 
Line 4:
{{collection|99 Bottles of Beer}}
[[99 Bottles of Beer]] done in Prolog-languages
<!--
See [[99 Bottles of Beer/Prolog]]
-->
 
__toc__
 
=={{header|=Prolog}}===
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">bottles(0).
bottles(X):-
writef('%t bottles of beer on the wall \n',[X]),
Line 21 ⟶ 18:
bottles(XN).
 
:- bottles(99).</langsyntaxhighlight>
 
It is possible to extend the previous version so to handle singular and plurals of the word 'bottle':
 
<langsyntaxhighlight lang="prolog">bottles(0):- write('no more bottles of beer').
bottles(B) :-
dif(B,0), NewB is B - 1,
Line 40 ⟶ 37:
bottles(NewB).
 
:- bottles(99).</langsyntaxhighlight>
 
Another version that handles plural/not plural conditions.
 
<langsyntaxhighlight lang="prolog">line1(X):- line2(X),write(' on the wall').
line2(0):- write('no more bottles of beer').
line2(1):- write('1 bottle of beer').
Line 62 ⟶ 59:
bottles(XN).
:- bottles(99).</langsyntaxhighlight>
 
=={{header|=Visual Prolog}}===
<langsyntaxhighlight lang="visual prolog">
implement main
open core, std, console
Line 89 ⟶ 86:
 
goal
mainExe::run(main::run).</syntaxhighlight>
</lang>
9,476

edits