99 bottles of beer: Difference between revisions

fix syntax highlighting
(Add implementation in Uxntal)
(fix syntax highlighting)
(18 intermediate revisions by 8 users not shown)
Line 66:
 
=={{header|8th}}==
<syntaxhighlight lang="forthfactor">
\ 99 bottles of beer on the wall:
: allout "no more bottles" ;
: just-one "1 bottle" ;
: yeah! dup . " bottles" ;
 
[
"no more bottles" ,
' allout ,
' just- "one bottle" ,
( dup . " bottles" )
' yeah! ,
] var, bottles
 
: .bottles dup 2 n:min bottles @ swap caseof ;
: .beer dup 2 n:min .bottles . " of beer"@ .caseof ;
: .wall .beer " on the wall" . ;
: .take " Take one down and pass it around" . ;
: beers .wall ", " . .beer '; putc cr
n:1- 0 max .take ", " .
.wall '. putc cr drop ;
 
: .beer
' beers 1 99 loop- bye
.bottles . " of beer" . ;
 
: .wall
.beer " on the wall" . ;
 
: .take
" Take one down and pass it around" . ;
 
: beers
.wall ", " . .beer '; putc cr
n:1- 0 max .take ", " .
.wall '. putc cr drop ;
 
' beers 1 99 loop-
bye
</syntaxhighlight>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 215 ⟶ 222:
cl_demo_output=>display( ).
</syntaxhighlight>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN bottles n:
SELECT:
n<0: RETURN "99 bottles"
n=0: RETURN "No more bottles"
n=1: RETURN "1 bottle"
n>1: RETURN "`n` bottles"
 
HOW TO SING VERSE n:
WRITE "`bottles n` of beer on the wall,"/
WRITE "`bottles n` of beer,"/
SELECT:
n=0: WRITE "Go to the store and buy some more,"/
n=1: WRITE "Take it down and pass it around,"/
n>1: WRITE "Take one down and pass it around,"/
WRITE "`bottles (n-1)` of beer on the wall."/
WRITE /
 
FOR n IN {0..99}:
SING VERSE 99-n</syntaxhighlight>
 
=={{header|ACL2}}==
Line 959 ⟶ 987:
 
-- At the prompt, type 'N beer !' (no quotes), where N is the number of stanzas you desire</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* Pointing out some interesting things:
* - BY 0 subclause of VARYING (illegal in some COBOL dialects)
* - PERFORM THROUGH with internal/external GO TOs
* - using non-reserved keywords (END, DATA)
* - ALTER (works the same way in COBOL)
* - fall-through from MANY-BOTTLES
* - the last NEXT SENTENCE does nothing (plays the role of EXIT)
IDENTIFICATION DIVISION.
PROGRAM-ID. 99 BOTTLES.
DATA DIVISION.
01 DATA PICTURE IS 999.
PROCEDURE DIVISION.
LOOP VARYING DATA FROM 99 BY 0
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY DATA "bottles of beer"
DISPLAY "Take one down, pass it around"
SUBTRACT 1 FROM DATA
IF DATA = 1
THEN ALTER COUNT-BOTTLES TO PROCEED TO SINGLE-BOTTLE
END
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY ""
END.
NO-BOTTLES-LEFT.
DISPLAY "No bottles of beer on the wall"
DISPLAY ""
DISPLAY "Go to the store and buy some more"
DISPLAY "99 bottles of beer on the wall".
STOP.
COUNT-BOTTLES.
GO TO MANY-BOTTLES.
SINGLE-BOTTLE.
DISPLAY DATA "bottle of beer on the wall".
GO TO NO-BOTTLES-LEFT.
MANY-BOTTLES.
DISPLAY DATA "bottles of beer on the wall".
END.
NEXT SENTENCE.
</syntaxhighlight>
 
=={{header|BASIC}}==
Line 1,445 ⟶ 1,515:
p "One bottle of beer on the wall, one bottle of beer!"
p "Take one down, pass it around, no more bottles of beer on the wall."</syntaxhighlight>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/Number .
:import std/String .
 
main [y [[=?0 case-end case-rec]] (+99)]
case-rec n ++ t1 ++ n ++ t2 ++ t3 ++ n ++ t1 ++ "\n" ++ (1 --0)
n number→string 0
t1 " bottles of beer on the wall\n"
t2 " bottles of beer\n"
t3 "Take one down, pass it around\n"
case-end empty
</syntaxhighlight>
 
=={{header|BQN}}==
Line 1,946 ⟶ 2,031:
WriteLine("Go to the store to buy some more, 99 bottles of beer on the wall...");
}</syntaxhighlight>
 
=={{header|C/vFP16}}==
<syntaxhighlight
lang="cpp">#pragma SCH_64_16_IFP
#import <jobsched.c>
 
__attr(@canschedule)
volatile constricts async UVOID <__INVAR const T>base_000000 __PCON(
impure VFCTX_t^ ct_base,
impure MCHR_t^ sched_arg,
__LVAR <const T>XVF_fntype_t^ f,
<out VF_QSWitch_t>XVF_fn_t^ switchctx
) __ARGFILL {
VF_Xsched_ILock(ct_base, $->sched);
 
captured __VFObj <>VF_KeDbg^ ki = VF_Xg_KeDbg_Instance();
 
captured deferred <__VF_T_Auto>__VF_Auto^ vfke = copyof VF_KeDbg_GetRstream<MCHR_t^>(captures ki);
VF_Gsched_SOBFree(sched_arg);
VF_Gsched_Alloc_U16(65535);
VF_Msched_MChr_lim(1496);
VF_Osched_Begin();
VF_Fsched_Add2(%beer_000099);
 
VF_Xsched_IUnlock(ct_base, $->sched);
$switchctx(IMPURE_CTX, %beer_000099(%vfke));
}
 
__attr(@eUsesIo)
impure constricts UVOID synchronized beer_000099(
impure __noinline <MCHR_t^>RIGHTSTREAM_t^ outrs
) __NFILL {
pure UVOID^ uvid = __attr(@purify) $UVOID.;
while ( 99 > ((volatile NUM_t)^(NUM_t^)(uvid))++ ) {
VF_STM_Out_NUM((NUM_t^)uvid);
VF_STM_Out_x(__Dynamic C"bottles on the wall.\nPut one down, pass it around\n");
}
return $__;
}
</syntaxhighlight>
 
=={{header|C++}}==
Line 9,406 ⟶ 9,534:
 
=={{header|Oxygene}}==
<syntaxhighlight lang="oxygenepascal">
namespace ConsoleApplication2;
 
Line 9,440 ⟶ 9,568:
end;
 
end.
</syntaxhighlight>
 
 
This version uses top-level declarations, string interpolation along with more idiomatic Object Pascal syntax vs C#.Net syntax:
 
<syntaxhighlight lang="pascal">
namespace _99_beers;
 
method bottles(number: Integer): String;
begin
if (number = 1) then
Result := "bottle"
else
Result := "bottles";
end;
 
begin
for n: Integer := 99 downto 1 do
begin
writeLn($"{n} {bottles(n)} of beer on the wall,");
writeLn($"{n} {bottles(n)} of beer,");
writeLn($"Take one down, and pass it around,");
writeLn($"{n-1} {bottles(n-1)} of beer on the wall.");
writeLn();
end;
readLn;
end.
</syntaxhighlight>
Line 9,500 ⟶ 9,655:
=={{header|Pascal}}==
See [[99 Bottles of Beer/Pascal]]
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="pascal">
begin
for var i:=99 to 1 step -1 do
begin
Println(i,'bottles of beer on the wall');
Println(i,'bottles of beer');
Println('Take one down, pass it around');
Println(i-1,'bottles of beer on the wall');
Println
end;
end.
</syntaxhighlight>
 
 
This version demonstrates uses of 'writeLn' vs 'Println' as well as string interpolation:
 
<syntaxhighlight lang="pascal">
begin
for var i:=99 to 1 step -1 do
begin
writeLn($'{i} bottles of beer on the wall');
writeLn($'{i} bottles of beer');
writeLn($'Take one down, pass it around');
writeLn($'{i-1}bottles of beer on the wall');
writeLn
end;
end.
</syntaxhighlight>
 
=={{header|Perl}}==
Line 13,364 ⟶ 13,549:
( >> )
&end
;dict/of-beer !<print-string>
( >> )
 
@<print-string> ( str -- )
Line 13,629 ⟶ 13,815:
Fails the task definition for more song, includes the no beer verse.
 
<syntaxhighlight lang="gov">// 99 bottles of V
module main
 
Line 14,040 ⟶ 14,226:
# ys 99-bottles.ys [<count>]
 
defn main(&[number]=99):
number =: number || 99
each [n (number .. 1)]:
say: paragraph(n)
 
defn paragraph(num): |
$(bottles (num) of beer on the wall,
$(bottles (num) of beer.
Take one down, pass it around.
$(bottles (num - 1)) of beer on the wall.
 
defn bottles(n):
cond:
(n == 0) : "'No more bottles"'
(n == 1) : "'1 bottle"'
=> : "$n bottles"
</syntaxhighlight>