The Twelve Days of Christmas: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎{{header|q}}: removed redundant iteration and variable)
 
(40 intermediate revisions by 21 users not shown)
Line 14: Line 14:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V gifts = ‘A partridge in a pear tree.
<syntaxhighlight lang="11l">V gifts = |‘A partridge in a pear tree.
Two turtle doves
Two turtle doves
Three french hens
Three french hens
Four calling birds
Four calling birds
Five golden rings
Five golden rings
Six geese a-laying
Six geese a-laying
Seven swans a-swimming
Seven swans a-swimming
Eight maids a-milking
Eight maids a-milking
Nine ladies dancing
Nine ladies dancing
Ten lords a-leaping
Ten lords a-leaping
Eleven pipers piping
Eleven pipers piping
Twelve drummers drumming’.split("\n")
Twelve drummers drumming’.split("\n")


V days = ‘first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth’.split(‘ ’)
V days = ‘first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth’.split(‘ ’)
Line 32: Line 32:
V n = L.index + 1
V n = L.index + 1
V g = reversed(gifts[0 .< n])
V g = reversed(gifts[0 .< n])
print("\nOn the #. day of Christmas\nMy true love gave to me:\n".format(day)‘’g[0 .< (len)-1].join("\n")‘’(I n > 1 {" and\n"g.last} E g.last))</lang>
print("\nOn the #. day of Christmas\nMy true love gave to me:\n".format(day)‘’g[0 .< (len)-1].join("\n")‘’(I n > 1 {" and\n"g.last} E g.last))</syntaxhighlight>


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==


<lang 8080asm>CR: equ 13
<syntaxhighlight lang="8080asm">CR: equ 13
LF: equ 10
LF: equ 10
puts: equ 9 ; CP/M function to write a string to the console
puts: equ 9 ; CP/M function to write a string to the console
Line 109: Line 109:
two: db 'Two turtle doves and',CR,LF
two: db 'Two turtle doves and',CR,LF
one: db 'A partridge in a pear tree.',CR,LF
one: db 'A partridge in a pear tree.',CR,LF
db CR,LF,'$'</lang>
db CR,LF,'$'</syntaxhighlight>


=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
{{trans|8080 Assembly}}
{{trans|8080 Assembly}}


<lang asm>CR: equ 10
<syntaxhighlight lang="asm">CR: equ 10
LF: equ 13
LF: equ 13
puts: equ 9 ; MS-DOS syscall to print string
puts: equ 9 ; MS-DOS syscall to print string
Line 176: Line 176:
db CR,LF,'$'
db CR,LF,'$'
.tab: dw .n1,.n2,.n3,.n4,.n5,.n6
.tab: dw .n1,.n2,.n3,.n4,.n5,.n6
dw .n7,.n8,.n9,.n10,.n11,.n12</lang>
dw .n7,.n8,.n9,.n10,.n11,.n12</syntaxhighlight>

=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN

PROC Main()
DEFINE PTR="CARD"
PTR ARRAY num(12),obj(12)
BYTE i,j

num(0)="first" num(1)="second" num(2)="third"
num(3)="fourth" num(4)="fifth" num(5)="sixth"
num(6)="seventh" num(7)="eight" num(8)="ninth"
num(9)="tenth" num(10)="eleventh" num(11)="Twelfth"

obj(0)="And a partridge in a pear tree."
obj(1)="Two turtle doves"
obj(2)="Three french hens"
obj(3)="Four calling birds"
obj(4)="Five golden rings"
obj(5)="Six geese a-laying"
obj(6)="Seven swans a-swimming"
obj(7)="Eight maids a-milking"
obj(8)="Nine ladies dancing"
obj(9)="Ten lords a-leaping"
obj(10)="Eleven pipers piping"
obj(11)="Twelve drummers drumming"

FOR i=0 TO 11
DO
PrintF("On the %S day of Christmas,%E",num(i))
PrintE("My true love gave to me:")
IF i=0 THEN
PrintE("A partridge in a pear tree.")
ELSE
j=i+1
WHILE j>0
DO
j==-1
PrintE(obj(j))
OD
FI
PutE()
Wait(50)
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/The_Twelve_Days_of_Christmas.png Screenshot from Atari 8-bit computer]
<pre>
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves
And a partridge in a pear tree.

...

On the Twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.
</pre>


=={{header|ActionScript}}==
=={{header|ActionScript}}==
Line 184: Line 262:
{{works with|Flash Player|Flash Player|10}}
{{works with|Flash Player|Flash Player|10}}
{{works with|Adobe AIR|AIR|1.5}} (Although the code can work in Flash Player 9 by replacing the Vectors with Arrays)
{{works with|Adobe AIR|AIR|1.5}} (Although the code can work in Flash Player 9 by replacing the Vectors with Arrays)
<lang ActionScript>package {
<syntaxhighlight lang="actionscript">package {
import flash.display.Sprite;
import flash.display.Sprite;
Line 294: Line 372:
}
}
}</lang>
}</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;


Line 333: Line 411:
end loop;
end loop;
end Twelve_Days_Of_Christmas;
end Twelve_Days_Of_Christmas;
</syntaxhighlight>
</lang>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{Works with|ALGOL 68 Genie}}
{{Works with|ALGOL 68 Genie}}
<lang algol68>BEGIN
<syntaxhighlight lang="algol68">BEGIN
[]STRING labels = ("first", "second", "third", "fourth",
[]STRING labels = ("first", "second", "third", "fourth",
"fifth", "sixth", "seventh", "eighth",
"fifth", "sixth", "seventh", "eighth",
Line 362: Line 440:
print(newline)
print(newline)
OD
OD
END</lang>
END</syntaxhighlight>


{{Out}}
{{Out}}
Line 387: Line 465:
Two turtle doves, and
Two turtle doves, and
A partridge in a pear tree.</pre>
A partridge in a pear tree.</pre>

=={{header|APL}}==
{{works with|Dyalog APL}}
{{trans|Forth}}
<syntaxhighlight lang="apl">ord ← { ⍵ ⌷ 'first' 'second' 'third' 'fourth' 'fifth' 'sixth' 'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth' }

gift ← { ⍵ ⌷ 'A partridge in a pear tree.' 'Two turtle doves, and' 'Three French hens,' 'Four calling birds,' 'Five gold rings,' 'Six geese a-laying,' 'Seven swans a-swimming,' 'Eight maids a-milking,' 'Nine ladies dancing,' 'Ten lords a-leaping,' 'Eleven pipers piping,' 'Twelve drummers drumming,' }

day ← { ⎕ ← (⎕ucs 10),'On the',(ord ⍵),'day of Christmas, my true love sent to me:' ⋄ { ⎕ ← gift ⍵ } ¨ ⌽⍳⍵ }

day ¨ ⍳12</syntaxhighlight>

{{Out}}
<pre>
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.


On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.


On the third day of Christmas, my true love sent to me:
Three French hens,
Two turtle doves, and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.</pre>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
===Iterative===
===Iterative===
<lang applescript>set gifts to {"A partridge in a pear tree.", "Two turtle doves, and", ¬
<syntaxhighlight lang="applescript">set gifts to {"A partridge in a pear tree.", "Two turtle doves, and", ¬
"Three French hens,", "Four calling birds,", ¬
"Three French hens,", "Four calling birds,", ¬
"Five gold rings,", "Six geese a-laying,", ¬
"Five gold rings,", "Six geese a-laying,", ¬
Line 406: Line 527:
end repeat
end repeat
log ""
log ""
end repeat</lang>
end repeat</syntaxhighlight>


{{Out}}
{{Out}}
Line 437: Line 558:
Drawing on some functional primitives, and post-Yosemite AppleScript's ability to import Foundation classes:
Drawing on some functional primitives, and post-Yosemite AppleScript's ability to import Foundation classes:


<lang AppleScript>use framework "Foundation"
<syntaxhighlight lang="applescript">use framework "Foundation"


property pstrGifts : "A partridge in a pear tree, Two turtle doves, Three French hens, " & ¬
property pstrGifts : "A partridge in a pear tree, Two turtle doves, Three French hens, " & ¬
Line 572: Line 693:
((ca's NSString's stringWithString:(str))'s ¬
((ca's NSString's stringWithString:(str))'s ¬
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper</lang>
end toUpper</syntaxhighlight>


{{Out}}
{{Out}}
Line 600: Line 721:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>gifts: [
<syntaxhighlight lang="rebol">gifts: [
"A partridge in a pear tree."
"A partridge in a pear tree."
"Two turtle doves"
"Two turtle doves"
Line 626: Line 747:
-> capitalize last g
-> capitalize last g
print ""
print ""
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 745: Line 866:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>nth := ["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]
<syntaxhighlight lang="autohotkey">nth := ["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]
lines := ["A partridge in a pear tree."
lines := ["A partridge in a pear tree."
,"Two turtle doves and"
,"Two turtle doves and"
Line 766: Line 887:
full:= full . top . "`n" . mid . ((A_Index<lines.MaxIndex())?"`n":"")
full:= full . top . "`n" . mid . ((A_Index<lines.MaxIndex())?"`n":"")
}
}
MsgBox % full</lang>
MsgBox % full</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
BEGIN {
BEGIN {
Line 795: Line 916:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 826: Line 947:


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>:: The Twelve Days of Christmas
<syntaxhighlight lang="dos">:: The Twelve Days of Christmas
:: Batch File Implementation
:: Batch File Implementation


Line 875: Line 996:
echo(
echo(
)
)
exit /b</lang>
exit /b</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT I,J: DEFSTR N,V: DIM N(12),V(12)

<lang basic>10 DEFINT I,J: DEFSTR N,V: DIM N(12),V(12)
20 FOR I=1 TO 12: READ N(I): NEXT
20 FOR I=1 TO 12: READ N(I): NEXT
30 FOR I=1 TO 12: READ V(I): NEXT
30 FOR I=1 TO 12: READ V(I): NEXT
Line 902: Line 1,022:
210 DATA "Ten lords a-leaping"
210 DATA "Ten lords a-leaping"
220 DATA "Eleven pipers piping"
220 DATA "Eleven pipers piping"
230 DATA "Twelve drummers drumming"</lang>
230 DATA "Twelve drummers drumming"</syntaxhighlight>

==={{header|Applesoft BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.

==={{header|BASIC256}}===
<syntaxhighlight lang="qbasic">dim dia$ = {"first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"}

dim gift$ = {"A partridge in a pear tree.","Two turtle doves and","Three french hens","Four calling birds","Five golden rings","Six geese a-laying","Seven swans a-swimming","Eight maids a-milking","Nine ladies dancing","Ten lords a-leaping","Eleven pipers piping","Twelve drummers drumming"}

for i = 0 to 11
print "On the "; dia$[i]; " dia of Christmas,"
print "My true love gave to me:"
for j = i to 1 step -1
print gift$[j]
next j
print
next i</syntaxhighlight>

==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.

==={{header|Commodore BASIC}}===
Similar to other 8-bit BASICs shown here. This adds a delay and grammar adjustments. Color coding specific to Commodore 64/128.
<syntaxhighlight lang="gwbasic">1 rem rosetta code
2 rem twelve days of christmas
5 print chr$(14):poke 53280,13:poke 53281,1
10 dim a$(12),ex$(12):a=1
15 for i=1 to 12:read a$(i),ex$(i):next i
20 for c=1 to 12
25 print chr$(147):print chr$(30);" The Twelve Days of Christmas":print
30 print chr$(28);" On the ";a$(c);" day of Christmas":gosub 200
35 print " my true love gave to me: ":print:gosub 200
40 for bc=c to 1 step -1
45 print tab(4);
50 if c=1 then print "A ";
55 if c>1 and bc=1 then print "And a ";
60 print ex$(bc);
65 if bc=1 or bc=5 then print "!":gosub 200:gosub 200:goto 75
70 print ","
75 gosub 200
80 next bc
85 rem pause for verse change
90 print:for t=1 to 500:next t
95 next c
100 end

200 for t=1 to 750:next t:return:rem generic delay

1000 rem lyrics
1010 data "first","partridge in a pear tree"
1020 data "second","Two turtle doves"
1030 data "third","Three french hens"
1040 data "fourth","Four calling birds"
1050 data "fifth","Five golden rings"
1060 data "sixth","Six geese a-laying"
1070 data "seventh","Seven swans a-swimming"
1080 data "eighth","Eight maids a-milking"
1090 data "ninth","Nine ladies dancing"
1100 data "tenth","Ten lords a-leaping"
1110 data "eleventh","Eleven pipers piping"
1120 data "twelfth","Twelve drummers drumming"</syntaxhighlight>

==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">100 CLS : REM 100 HOME for Applesoft BASIC
110 DIM D$(12)
120 DIM G$(12)
130 FOR I = 1 TO 12 : READ D$(I) : NEXT I
140 FOR I = 1 TO 12 : READ G$(I) : NEXT I
150 FOR I = 1 TO 12
160 PRINT "On the ";D$(I);" day of Christmas,"
170 PRINT "My true love gave to me:"
180 FOR J = I TO 1 STEP -1 : PRINT G$(J) : NEXT J
190 PRINT
200 NEXT I
210 END
220 DATA "first","second","third","fourth","fifth","sixth"
230 DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
240 DATA "A partridge in a pear tree."
250 DATA "Two turtle doves and"
260 DATA "Three french hens"
270 DATA "Four calling birds"
280 DATA "Five golden rings"
290 DATA "Six geese a-laying"
300 DATA "Seven swans a-swimming"
310 DATA "Eight maids a-milking"
320 DATA "Nine ladies dancing"
330 DATA "Ten lords a-leaping"
340 DATA "Eleven pipers piping"
350 DATA "Twelve drummers drumming"</syntaxhighlight>

==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.

==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.

==={{header|True BASIC}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">DATA "first","second","third","fourth","fifth","sixth"
DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
DATA "A partridge in a pear tree."
DATA "Two turtle doves and"
DATA "Three french hens"
DATA "Four calling birds"
DATA "Five golden rings"
DATA "Six geese a-laying"
DATA "Seven swans a-swimming"
DATA "Eight maids a-milking"
DATA "Nine ladies dancing"
DATA "Ten lords a-leaping"
DATA "Eleven pipers piping"
DATA "Twelve drummers drumming"

DIM day$(12), gift$(12)
FOR i = 1 TO 12
READ day$(i)
NEXT i
FOR i = 1 TO 12
READ gift$(i)
NEXT i

FOR i = 1 TO 12
PRINT "On the "; day$(i); " day of Christmas,"
PRINT "My true love gave TO me:"
FOR j = i TO 1 STEP -1
PRINT gift$(j)
NEXT j
PRINT
NEXT i
END</syntaxhighlight>

==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "The Twelve Days of Christmas"
VERSION "0.0000"

DECLARE FUNCTION Entry ()

FUNCTION Entry ()
DIM day$[11]
day$[0] = "first"
day$[1] = "second"
day$[2] = "third"
day$[3] = "fourth"
day$[4] = "fifth"
day$[5] = "sixth"
day$[6] = "seventh"
day$[7] = "eighth"
day$[8] = "ninth"
day$[9] = "tenth"
day$[10] = "eleventh"
day$[11] = "twelfth"

DIM gift$[11]
gift$[0] = "A partridge in a pear tree."
gift$[1] = "Two turtle doves and"
gift$[2] = "Three french hens"
gift$[3] = "Four calling birds"
gift$[4] = "Five golden rings"
gift$[5] = "Six geese a-laying"
gift$[6] = "Seven swans a-swimming"
gift$[7] = "Eight maids a-milking"
gift$[8] = "Nine ladies dancing"
gift$[9] = "Ten lords a-leaping"
gift$[10] = "Eleven pipers piping"
gift$[11] = "Twelve drummers drumming"

FOR i = 0 TO 11
PRINT "On the "; day$[i]; " day of Christmas,"
PRINT "My true love gave to me:"
FOR J = i TO 0 STEP -1
PRINT gift$[J]
NEXT J
PRINT
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>

==={{header|Yabasic}}===
<syntaxhighlight lang="qbasic">dim day$(12), gift$(12)
for i = 1 to 12: read day$(i): next i
for i = 1 to 12: read gift$(i): next i
for i = 1 to 12
print "On the ", day$(i), " day of Christmas,"
print "My true love gave to me:"
for j = i to 1 step -1: print gift$(j): next j
print
next i
end

data "first","second","third","fourth","fifth","sixth"
data "seventh","eighth","ninth","tenth","eleventh","twelfth"
data "A partridge in a pear tree."
data "Two turtle doves and"
data "Three french hens"
data "Four calling birds"
data "Five golden rings"
data "Six geese a-laying"
data "Seven swans a-swimming"
data "Eight maids a-milking"
data "Nine ladies dancing"
data "Ten lords a-leaping"
data "Eleven pipers piping"
data "Twelve drummers drumming"</syntaxhighlight>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang BCPL>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


let ordinal(n) =
let ordinal(n) =
Line 936: Line 1,270:
$)
$)


let start() be for n=1 to 12 do verse(n)</lang>
let start() be for n=1 to 12 do verse(n)</syntaxhighlight>


=={{header|Befunge}}==
=={{header|Befunge}}==
This is essentially the same algorithm as [[Old_lady_swallowed_a_fly#Befunge|Old lady swallowed a fly]] - just a different set of phrases and a simpler song pattern.
This is essentially the same algorithm as [[Old_lady_swallowed_a_fly#Befunge|Old lady swallowed a fly]] - just a different set of phrases and a simpler song pattern.
<lang befunge>0246*+00p20#v_:#`2#g+#0:#0<>\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
<syntaxhighlight lang="befunge">0246*+00p20#v_:#`2#g+#0:#0<>\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#11#\0#50#< g2-:00p4v >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
>-#11#\0#50#< g2-:00p4v >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$<
^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 948: Line 1,282:
-swimming(seventh7|Eight maids a-milking'eighth5|Nine ladies dancing&ninth5|Ten
-swimming(seventh7|Eight maids a-milking'eighth5|Nine ladies dancing&ninth5|Ten
lords a-leaping&tenth6|Eleven pipers piping)eleventh:|Twelve drummers drumming
lords a-leaping&tenth6|Eleven pipers piping)eleventh:|Twelve drummers drumming
(twelfth</lang>
(twelfth</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat>( first
<syntaxhighlight lang="bracmat">( first
second
second
third
third
Line 988: Line 1,322:
)
)
)
)
);</lang>
);</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
#include<stdio.h>
Line 1,041: Line 1,375:
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


public class TwelveDaysOfChristmas {
public class TwelveDaysOfChristmas {
Line 1,086: Line 1,420:
}
}


}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <array>
#include <array>
#include <string>
#include <string>
Line 1,146: Line 1,480:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
{{trans|Raku}}
{{trans|Raku}}
<lang clojure>(let
<syntaxhighlight lang="clojure">(let
[numbers '(first second third fourth fifth sixth
[numbers '(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
seventh eighth ninth tenth eleventh twelfth)
Line 1,172: Line 1,506:
(dorun (for [n (range d -1 -1)]
(dorun (for [n (range d -1 -1)]
(println (nth gifts n))))))))
(println (nth gifts n))))))))
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
<pre>On the first day of Christmas, my true love sent to me:
Line 1,196: Line 1,530:
Two turtle doves and
Two turtle doves and
A partridge in a pear tree.</pre>
A partridge in a pear tree.</pre>

=={{header|CLU}}==
<syntaxhighlight lang="clu">christmas = cluster is carol
rep = null
own ordinals: array[string] := array[string]$[
"first", "second", "third", "fourth", "fifth",
"sixth", "seventh", "eighth", "ninth", "tenth",
"eleventh", "twelfth"
]
own gifts: array[string] := array[string]$[
"A partridge in a pear tree.",
"Two turtle doves, and",
"Three french hens,",
"Four calling birds,",
"Five golden rings,",
"Six geese a-laying,",
"Seven swans a-swimming,",
"Eight maids a-milking,",
"Nine ladies dancing,",
"Ten lords a-leaping,",
"Eleven pipers piping,",
"Twelve drummers drumming,"
]
verse = proc (s: stream, n: int)
stream$putl(s, "On the " || ordinals[n] || " day of Christmas,")
stream$putl(s, "My true love gave to me:")
for gift: int in int$from_to_by(n, 1, -1) do
stream$putl(s, gifts[gift])
end
stream$putl(s, "")
end verse
carol = proc (s: stream)
for n: int in int$from_to(1, 12) do
verse(s, n)
end
end carol
end christmas

start_up = proc ()
christmas$carol(stream$primary_output())
end start_up</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|GNU Cobol|2.0}}
{{works with|GNU Cobol|2.0}}
<lang cobol> >>SOURCE FREE
<syntaxhighlight lang="cobol"> >>SOURCE FREE
PROGRAM-ID. twelve-days-of-christmas.
PROGRAM-ID. twelve-days-of-christmas.


Line 1,242: Line 1,621:
END-PERFORM
END-PERFORM
.
.
END PROGRAM twelve-days-of-christmas.</lang>
END PROGRAM twelve-days-of-christmas.</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==


<lang lisp>let
<syntaxhighlight lang="lisp">let
((gifts '("A partridge in a pear tree." "Two turtle doves, and"
((gifts '("A partridge in a pear tree." "Two turtle doves, and"
"Three French hens," "Four calling birds,"
"Three French hens," "Four calling birds,"
Line 1,259: Line 1,638:
(format t "~a~%" (nth gift gifts)))
(format t "~a~%" (nth gift gifts)))
(format t "~%")))
(format t "~%")))
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 1,286: Line 1,665:


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


var ordinals: [uint8][] := {
var ordinals: [uint8][] := {
Line 1,323: Line 1,702:
print_nl();
print_nl();
verse := verse + 1;
verse := verse + 1;
end loop;</lang>
end loop;</syntaxhighlight>


=={{header|Crystal}}==
=={{header|Crystal}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang ruby>days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split " "
<syntaxhighlight lang="ruby">days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split " "
gifts = "A partridge in a pear tree
gifts = "A partridge in a pear tree
Two turtle doves and
Two turtle doves and
Line 1,345: Line 1,724:
gifts[0, i + 1].reverse.each &->puts(String)
gifts[0, i + 1].reverse.each &->puts(String)
puts
puts
end</lang>
end</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
{{trans|Python}}
{{trans|Python}}
<lang d>immutable gifts =
<syntaxhighlight lang="d">immutable gifts =
"A partridge in a pear tree.
"A partridge in a pear tree.
Two turtle doves
Two turtle doves
Line 1,377: Line 1,756:
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
}
}
}</lang>
}</syntaxhighlight>


=={{header|dc}}==
=={{header|dc}}==
<lang dc>0
<syntaxhighlight lang="dc">0


d [first] r :n
d [first] r :n
Line 1,446: Line 1,825:


0 ll x
0 ll x
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 1,471: Line 1,850:
Two turtle doves and
Two turtle doves and
A partridge in a pear tree.</pre>
A partridge in a pear tree.</pre>

=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}


<syntaxhighlight lang="Delphi">


const GiftList: array [0..11] of string =(
'a partridge in a pear tree.',
'Two turtle doves',
'Three french hens',
'Four calling birds',
'Five golden rings',
'Six geese a-laying',
'Seven swans a-swimming',
'Eight maids a-milking',
'Nine ladies dancing',
'Ten lords a-leaping',
'Eleven pipers piping',
'Twelve drummers drumming');

const Cardinals: array [0..11] of string =
('first','second','third','forth',
'fifth','sixth','seventh','eight',
'ninth','tenth','eleventh','twelfth');

procedure DoOneDay(Memo: TMemo; Day: integer);
var S: string;
var I: integer;
begin
S:='On the '+Cardinals[Day]+' of Christmas ';
S:=S+'my true love gave to me'+CRLF;
for I:=Day downto 0 do
begin
if (Day>0) and (I=0) then S:=S+'and ';
S:=S+GiftList[I]+CRLF;
end;
Memo.Lines.Add(S);
end;

procedure TwelveDaysOfChristmas(Memo: TMemo);
var I: integer;
begin
for I:=0 to 12-1 do DoOneDay(Memo,I);
end;


</syntaxhighlight>
{{out}}
<pre>
On the first of Christmas my true love gave to me
a partridge in a pear tree.

On the second of Christmas my true love gave to me
Two turtle doves
and a partridge in a pear tree.

On the third of Christmas my true love gave to me
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the forth of Christmas my true love gave to me
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the fifth of Christmas my true love gave to me
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the sixth of Christmas my true love gave to me
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the seventh of Christmas my true love gave to me
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the eight of Christmas my true love gave to me
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the ninth of Christmas my true love gave to me
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the tenth of Christmas my true love gave to me
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the eleventh of Christmas my true love gave to me
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the twelfth of Christmas my true love gave to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.
Elapsed Time: 34.088 ms.
</pre>



=={{header|Dyalect}}==
=={{header|Dyalect}}==
<lang dyalect>let days = [
<syntaxhighlight lang="dyalect">let days = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth"
"tenth", "eleventh", "twelfth"
Line 1,498: Line 2,033:
}
}
print()
print()
}</lang>
}</syntaxhighlight>

=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
days$[] = [ "first" "second" "third" "forth" "fifth" "sixth" "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth" ]
gifts$[] &= "Twelve drummers drumming"
gifts$[] &= "Eleven pipers piping"
gifts$[] &= "Ten lords a-leaping"
gifts$[] &= "Nine ladies dancing"
gifts$[] &= "Eight maids a-milking"
gifts$[] &= "Seven swans a-swimming"
gifts$[] &= "Six geese a-laying"
gifts$[] &= "Five golden rings"
gifts$[] &= "Four calling birds"
gifts$[] &= "Three french hens"
gifts$[] &= "Two turtle doves and"
gifts$[] &= "A partridge in a pear tree."
for i = 1 to 12
print "On the " & days$[i] & " day of Christmas,"
print "My true love gave to me:"
for j = 13 - i to 12
print gifts$[j]
.
print ""
.
</syntaxhighlight>


=={{header|Eiffel}}==
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
class
APPLICATION
APPLICATION
Line 1,557: Line 2,117:


end
end
</syntaxhighlight>
</lang>


=={{header|Elena}}==
=={{header|Elena}}==
{{trans|C++}}
{{trans|C++}}
ELENA 5.0 :
ELENA 6.x :
<lang elena>import extensions;
<syntaxhighlight lang="elena">import extensions;
public program()
public program()
Line 1,586: Line 2,146:
};
};
for(int i := 0, i < 12, i += 1)
for(int i := 0; i < 12; i += 1)
{
{
console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");
console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");
Line 1,596: Line 2,156:
else
else
{
{
for(int j := i, j >= 0, j -= 1)
for(int j := i; j >= 0; j -= 1)
{
{
console.printLine(gifts[j])
console.printLine(gifts[j])
Line 1,604: Line 2,164:
console.printLine()
console.printLine()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>gifts = """
<syntaxhighlight lang="elixir">gifts = """
A partridge in a pear tree
A partridge in a pear tree
Two turtle doves and
Two turtle doves and
Line 1,629: Line 2,189:
Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
IO.puts ""
IO.puts ""
end)</lang>
end)</syntaxhighlight>


{{out}}
{{out}}
Line 1,660: Line 2,220:


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>-module(twelve_days).
<syntaxhighlight lang="erlang">-module(twelve_days).
-export([gifts_for_day/1]).
-export([gifts_for_day/1]).


Line 1,680: Line 2,240:
main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
lists:seq(1,12)).
lists:seq(1,12)).
</syntaxhighlight>
</lang>
{{Out}}<pre>On the first day of Christmas, my true love sent to me:
{{Out}}<pre>On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
A partridge in a pear tree.
Line 1,705: Line 2,265:


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
<lang fsharp>let gifts = [
<syntaxhighlight lang="fsharp">let gifts = [
"And a partridge in a pear tree";
"And a partridge in a pear tree";
"Two turtle doves";
"Two turtle doves";
Line 1,733: Line 2,293:
printf "\n"
printf "\n"
List.iter displayGifts [0..11]</lang>
List.iter displayGifts [0..11]</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: formatting io kernel math math.ranges qw sequences ;
<syntaxhighlight lang="factor">USING: formatting io kernel math math.ranges qw sequences ;
IN: rosetta-code.twelve-days-of-christmas
IN: rosetta-code.twelve-days-of-christmas


Line 1,769: Line 2,329:
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;


MAIN: twelve-days-of-christmas</lang>
MAIN: twelve-days-of-christmas</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,793: Line 2,353:
Three french hens,
Three french hens,
Two turtle doves, and
Two turtle doves, and
A partridge in a pear tree.
</pre>

=={{header|Fish}}==
<syntaxhighlight lang="fish">> 0 7 . (0,0): Vector. Jumps to main, then used for sub returns
> 0 f 5 + . (0,1): Print a NUL-terminated string
> 6 6 * 9 + f 8 + . (0,2): Pop N, push Nth (e.g. 1 -> "first")
> 0 f 8 + . (0,3): Pop N, push gift countdown starting from N.
> 0 f 1 + . (0,4): Jump to line in range 16-30

main:
> 1 \
/ a "On the " 0 <
\ "a" 4 0 p 0 1 .
> "b" 4 0 p : 0 2 .
> "c" 4 0 p 0 1 .
> \
/ " day of Christmas, my true love sent to me:" a 0 /
> "f" 4 0 p 0 1 .
> "1" 6 4 p "4" 4 0 p : 0 3 .
> "2" 6 4 p 0 1 .
> 1 + : c ) ?\ /
;

> : ?\ ~ 0 0 .
\ o / > 0 0 .
^ "first" 0 ~ \
> \ > 1 - : ?\ /
/ "A partridge in a pear tree." a 0 & < / / ^ "second" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "third" 0 ~ \
/ "Two turtle doves and" a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "fourth" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Three French hens," a & / / / ^ "fifth" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "sixth" 0 ~ \
/ "Four calling birds," a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "seventh" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Five gold rings," a & / / / ^ "eighth" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "ninth" 0 ~ \
/ "Six geese a-laying," a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "tenth" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Seven swans a-swimming," a & / / / ^ "eleventh" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ \ \
/ "Eight maids a-milking," a & / ^ "twelfth" 0 ~ /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Nine ladies dancing," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Ten lords a-leaping," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Eleven pipers piping," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Twelve drummers drumming," a & /
\ & ~ 0 0 .</syntaxhighlight>
{{Out}}
<pre>
On the first day of Christmas, my true love gave to me:
A partridge in a pear tree.

On the second day of Christmas, my true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]


On the twelfth day of Christmas, my true love gave to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.
A partridge in a pear tree.
</pre>
</pre>
Line 1,798: Line 2,445:
=={{header|Forth}}==
=={{header|Forth}}==
{{works with|GNU Forth}}
{{works with|GNU Forth}}
<lang forth>create ordinals s" first" 2, s" second" 2, s" third" 2, s" fourth" 2,
<syntaxhighlight lang="forth">create ordinals s" first" 2, s" second" 2, s" third" 2, s" fourth" 2,
s" fifth" 2, s" sixth" 2, s" seventh" 2, s" eighth" 2,
s" fifth" 2, s" sixth" 2, s" seventh" 2, s" eighth" 2,
s" ninth" 2, s" tenth" 2, s" eleventh" 2, s" twelfth" 2,
s" ninth" 2, s" tenth" 2, s" eleventh" 2, s" twelfth" 2,
Line 1,834: Line 2,481:
main
main
bye
bye
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 1,862: Line 2,509:
=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|FORTRAN|77}}
{{works with|Fortran|FORTRAN|77}}
<lang fortran> program twelve_days
<syntaxhighlight lang="fortran"> program twelve_days


character days(12)*8
character days(12)*8
Line 1,894: Line 2,541:
10 continue
10 continue
end
end
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 1,921: Line 2,568:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' version 10-01-2017
<syntaxhighlight lang="freebasic">' version 10-01-2017
' compile with: fbc -s console
' compile with: fbc -s console


Line 1,956: Line 2,603:
Print : 'Print "hit any key to end program"
Print : 'Print "hit any key to end program"
Sleep
Sleep
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre> On the first day of Christmas
<pre> On the first day of Christmas
Line 1,986: Line 2,633:
=={{header|Go}}==
=={{header|Go}}==
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,011: Line 2,658:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>def presents = ['A partridge in a pear tree.', 'Two turtle doves', 'Three french hens', 'Four calling birds',
<syntaxhighlight lang="groovy">def presents = ['A partridge in a pear tree.', 'Two turtle doves', 'Three french hens', 'Four calling birds',
'Five golden rings', 'Six geese a-laying', 'Seven swans a-swimming', 'Eight maids a-milking',
'Five golden rings', 'Six geese a-laying', 'Seven swans a-swimming', 'Eight maids a-milking',
'Nine ladies dancing', 'Ten lords a-leaping', 'Eleven pipers piping', 'Twelve drummers drumming']
'Nine ladies dancing', 'Ten lords a-leaping', 'Eleven pipers piping', 'Twelve drummers drumming']
Line 2,025: Line 2,672:
}
}
println()
println()
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
{{trans|F#}}
{{trans|F#}}
<lang haskell>gifts :: [String]
<syntaxhighlight lang="haskell">gifts :: [String]
gifts =
gifts =
[ "And a partridge in a pear tree!",
[ "And a partridge in a pear tree!",
Line 2,073: Line 2,720:


main :: IO ()
main :: IO ()
main = mapM_ verseOfTheDay [0 .. 11]</lang>
main = mapM_ verseOfTheDay [0 .. 11]</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
Line 2,180: Line 2,827:


Works in both languages.
Works in both languages.
<lang unicon>procedure main()
<syntaxhighlight lang="unicon">procedure main()
days := ["first","second","third","fourth","fifth","sixth","seventh",
days := ["first","second","third","fourth","fifth","sixth","seventh",
"eighth","ninth","tenth","eleventh","twelveth"]
"eighth","ninth","tenth","eleventh","twelveth"]
Line 2,192: Line 2,839:
every write("\nOn the ",days[day := 1 to 12]," day of Christmas my true love gave to me:") do
every write("\nOn the ",days[day := 1 to 12]," day of Christmas my true love gave to me:") do
every write(" ",gifts[day to 1 by -1])
every write(" ",gifts[day to 1 by -1])
end</lang>
end</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
<lang j>require 'strings' NB. not necessary for versions > j6
<syntaxhighlight lang="j">require 'strings' NB. not necessary for versions > j6


days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
Line 2,220: Line 2,867:
makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_
makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_


singCarol=: LF joinstring makeVerses</lang>
singCarol=: LF joinstring makeVerses</syntaxhighlight>

=={{header|Janet}}==
<syntaxhighlight lang="janet">(def days ["first" "second" "third"
"fourth" "fifth" "sixth"
"seventh" "eighth" "ninth"
"tenth" "eleventh" "twelfth"])
(def gifts ["A partridge in a pear tree."
"Two turtle doves and"
"Three french hens"
"Four calling birds"
"Five golden rings"
"Six geese a-laying"
"Seven swans a-swimming"
"Eight maids a-milking"
"Nine ladies dancing"
"Ten lords a-leaping"
"Eleven pipers piping"
"Twelve drummers drumming"])
(var v "")
(eachp [i d] days
(print "On the " d " day of Christmas")
(print "My true love gave to me")
(set v (string (in gifts i) "\n" v))
(print v))</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>public class TwelveDaysOfChristmas {
<syntaxhighlight lang="java">public class TwelveDaysOfChristmas {


final static String[] gifts = {
final static String[] gifts = {
Line 2,248: Line 2,919:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
<lang JavaScript>
var days = [
var days = [
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,294: Line 2,965:
song = verses.join('\n\n');
song = verses.join('\n\n');
document.write(song);
document.write(song);
</syntaxhighlight>
</lang>




Alternatively, in a functional style of JavaScript, we can define the ancient song "strPrepn the lstOrdinal[i] strUnit of strHoliday" as an expression, and return that expression in a human-legible and machine-parseable JSON string translation, for further analysis and processing :-)
Alternatively, in a functional style of JavaScript, we can define the ancient song "strPrepn the lstOrdinal[i] strUnit of strHoliday" as an expression, and return that expression in a human-legible and machine-parseable JSON string translation, for further analysis and processing :-)


<lang JavaScript>JSON.stringify(
<syntaxhighlight lang="javascript">JSON.stringify(
(function (
(function (
strPrepn,
strPrepn,
Line 2,373: Line 3,044:
'On', 'Christmas', 'day', 'my true love', 'gave to', 'me'
'On', 'Christmas', 'day', 'my true love', 'gave to', 'me'
), null, 2
), null, 2
);</lang>
);</syntaxhighlight>


Note that the Google Closure compiler's translation of this would be half the size, but rather less legible.
Note that the Google Closure compiler's translation of this would be half the size, but rather less legible.
(It does make interesting suggestions though – the semi-colon segmentation of the verses below is a trick that might be worth remembering).
(It does make interesting suggestions though – the semi-colon segmentation of the verses below is a trick that might be worth remembering).


<lang JavaScript>JSON.stringify(function (h, k, l, f, m, n) {
<syntaxhighlight lang="javascript">JSON.stringify(function (h, k, l, f, m, n) {
var c =
var c =
"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
Line 2,399: Line 3,070:
0 : 1)))]);
0 : 1)))]);
}, []);
}, []);
}("On", "Christmas", "day", "my true love", "gave to", "me"), null, 2);</lang>
}("On", "Christmas", "day", "my true love", "gave to", "me"), null, 2);</syntaxhighlight>


Formatted JSON output (the expanded and Closure-compiled versions above both yield the same output).
Formatted JSON output (the expanded and Closure-compiled versions above both yield the same output).


<syntaxhighlight lang="javascript">[
<lang JavaScript>[
[
[
"On the first day of Christmas",
"On the first day of Christmas",
Line 2,442: Line 3,113:
//... etc.
//... etc.


]</lang>
]</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
<lang jq>[ "one", "two", "three", "four", "five", "six",
<syntaxhighlight lang="jq">[ "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
"seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
| [ "first", "second", "third", "fourth", "fifth", "sixth",
| [ "first", "second", "third", "fourth", "fifth", "sixth",
Line 2,459: Line 3,130:
" " + $gifts[$j] + if $j > 0 then "," else "\n" end]
" " + $gifts[$j] + if $j > 0 then "," else "\n" end]
| join("\n"))
| join("\n"))
</syntaxhighlight>
</lang>


Run with <pre>jq -rnf programfile.jq</pre> to yield this result:
Run with <pre>jq -rnf programfile.jq</pre> to yield this result:
Line 2,496: Line 3,167:
=={{header|Jsish}}==
=={{header|Jsish}}==
Based on Javascript entry, almost identical, added unitTest.
Based on Javascript entry, almost identical, added unitTest.
<lang javascript>#!/usr/bin/env jsish
<syntaxhighlight lang="javascript">#!/usr/bin/env jsish
"use strict";
"use strict";


Line 2,644: Line 3,315:
And a partridge in a pear tree
And a partridge in a pear tree
=!EXPECTEND!=
=!EXPECTEND!=
*/</lang>
*/</syntaxhighlight>


{{out}}
{{out}}
Line 2,652: Line 3,323:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia># v0.6.0
<syntaxhighlight lang="julia"># v0.6.0


function printlyrics()
function printlyrics()
Line 2,684: Line 3,355:
end
end


printlyrics()</lang>
printlyrics()</syntaxhighlight>


{{out}}
{{out}}
Line 2,715: Line 3,386:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|C#}}
{{trans|C#}}
<lang scala>enum class Day {
<syntaxhighlight lang="scala">enum class Day {
first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth;
first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth;
val header = "On the " + this + " day of Christmas, my true love sent to me\n\t"
val header = "On the " + this + " day of Christmas, my true love sent to me\n\t"
Line 2,735: Line 3,406:


Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
}</lang>
}</syntaxhighlight>


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def days
{def days
first second third fourth fifth sixth
first second third fourth fifth sixth
Line 2,790: Line 3,461:
Two turtle doves and
Two turtle doves and
A partridge in a pear tree.
A partridge in a pear tree.
</syntaxhighlight>
</lang>


=={{header|Logo}}==
=={{header|Logo}}==


<lang logo>make "numbers [first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth]
<syntaxhighlight lang="logo">make "numbers [first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth]
make "gifts [[And a partridge in a pear tree] [Two turtle doves] [Three French hens]
make "gifts [[And a partridge in a pear tree] [Two turtle doves] [Three French hens]
[Four calling birds] [Five gold rings] [Six geese a-laying]
[Four calling birds] [Five gold rings] [Six geese a-laying]
Line 2,814: Line 3,485:
]
]
]
]
bye</lang>
bye</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,843: Line 3,514:
=={{header|LOLCODE}}==
=={{header|LOLCODE}}==
{{works with|LCI 0.10}}
{{works with|LCI 0.10}}
<syntaxhighlight lang="text">HAI 1.2
<lang>CAN HAS STDIO?
CAN HAS STDIO?
HAI 1.2


I HAS A Dayz ITZ A BUKKIT
I HAS A Dayz ITZ A BUKKIT
Line 2,895: Line 3,566:
IM OUTTA YR Outer
IM OUTTA YR Outer
KTHXBYE</lang>
KTHXBYE</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,923: Line 3,594:


=={{header|Lua}}==
=={{header|Lua}}==
<syntaxhighlight lang="lua">
<lang Lua>
local days = {
local days = {
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,962: Line 3,633:


print(table.concat(verses, '\n\n'))
print(table.concat(verses, '\n\n'))
</syntaxhighlight>
</lang>


=={{header|MAD}}==
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE CAROL
.MCALL .TTYOUT,.EXIT
CAROL:: CLR R5
1$: MOV #ONTHE,R1
JSR PC,PRINT
MOV ORDTAB(R5),R1
JSR PC,PRINT
MOV #DAYOF,R1
JSR PC,PRINT
MOV VRSTAB(R5),R1
JSR PC,PRINT
ADD #2,R5
CMP R5,#^D24
BLT 1$
.EXIT


PRINT: MOVB (R1)+,R0
<lang MAD> NORMAL MODE IS INTEGER
.TTYOUT
BNE PRINT
RTS PC

ONTHE: .ASCIZ /On the /
ORDTAB: .WORD 1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
1$: .ASCIZ /first/
2$: .ASCIZ /second/
3$: .ASCIZ /third/
4$: .ASCIZ /fourth/
5$: .ASCIZ /fifth/
6$: .ASCIZ /sixth/
7$: .ASCIZ /seventh/
8$: .ASCIZ /eighth/
9$: .ASCIZ /ninth/
10$: .ASCIZ /tenth/
11$: .ASCIZ /eleventh/
12$: .ASCIZ /twelfth/
DAYOF: .ASCIZ / day of Christmas, my true love gave to me:/<15><12>
VRSTAB: .WORD 1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
12$: .ASCII /Twelve drummers drumming/<15><12>
11$: .ASCII /Eleven pipers piping/<15><12>
10$: .ASCII /Ten lords a-leaping/<15><12>
9$: .ASCII /Nine ladies dancing/<15><12>
8$: .ASCII /Eight maids a-milking/<15><12>
7$: .ASCII /Seven swans a-swimming/<15><12>
6$: .ASCII /Six geese a-laying/<15><12>
5$: .ASCII /Five golden rings/<15><12>
4$: .ASCII /Four calling birds/<15><12>
3$: .ASCII /Three French hens/<15><12>
2$: .ASCII /Two turtle doves, and/<15><12>
1$: .ASCIZ /A partridge in a pear tree./<15><12><15><12>
.END CAROL</syntaxhighlight>


=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
THROUGH VERSE, FOR I=1, 1, I.G.12
THROUGH VERSE, FOR I=1, 1, I.G.12
Line 3,006: Line 3,729:
VECTOR VALUES MT = $*$
VECTOR VALUES MT = $*$
END OF PROGRAM
END OF PROGRAM
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<lang maple>gifts := ["Twelve drummers drumming",
<syntaxhighlight lang="maple">gifts := ["Twelve drummers drumming",
"Eleven pipers piping", "Ten lords a-leaping",
"Eleven pipers piping", "Ten lords a-leaping",
"Nine ladies dancing", "Eight maids a-milking",
"Nine ladies dancing", "Eight maids a-milking",
Line 3,023: Line 3,746:
end do;
end do;
printf("\n");
printf("\n");
end do;</lang>
end do;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,073: Line 3,796:
</pre>
</pre>


=={{header|Mathematica}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">daysarray = {"first", "second", "third", "fourth", "fifth", "sixth",
<lang Mathematica>
daysarray = {"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
giftsarray = {"And a partridge in a pear tree.", "Two turtle doves",
giftsarray = {"And a partridge in a pear tree.", "Two turtle doves",
Line 3,087: Line 3,809:
daysarray[[i]],
daysarray[[i]],
If[i == 1, "A partridge in a pear tree.",
If[i == 1, "A partridge in a pear tree.",
Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]
Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre style="height:55ex;overflow:scroll">
<pre style="height:55ex;overflow:scroll">
Line 3,191: Line 3,912:
Three french hens,
Three french hens,
Two turtle doves,
Two turtle doves,
And a partridge in a pear tree.
And a partridge in a pear tree.</pre>
</pre>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>days = ["first","second","third", "fourth","fifth","sixth",
<syntaxhighlight lang="miniscript">days = ["first","second","third", "fourth","fifth","sixth",
"seventh","eigth","nineth","tenth","eleventh","twelfth"]
"seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
Line 3,212: Line 3,932:
print " ----------"
print " ----------"
end for
end for
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,241: Line 3,961:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
<lang nim>import strutils, algorithm
<syntaxhighlight lang="nim">import strutils, algorithm


const
const
Line 3,263: Line 3,983:
var g = reversed(Gifts[0..n])
var g = reversed(Gifts[0..n])
echo "\nOn the ", day, " day of Christmas\nMy true love gave to me:\n",
echo "\nOn the ", day, " day of Christmas\nMy true love gave to me:\n",
g[0..^2].join("\n"), if n > 0: " and\n" & g[^1] else: capitalizeAscii(g[^1])</lang>
g[0..^2].join("\n"), if n > 0: " and\n" & g[^1] else: capitalizeAscii(g[^1])</syntaxhighlight>


{{out}}
{{out}}
Line 3,294: Line 4,014:
=={{header|Objeck}}==
=={{header|Objeck}}==
{{trans|C sharp|C#}}
{{trans|C sharp|C#}}
<lang objeck>
<syntaxhighlight lang="objeck">
class TwelveDaysOfChristmas {
class TwelveDaysOfChristmas {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 3,330: Line 4,050:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>days=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"];
<syntaxhighlight lang="parigp">days=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"];
gifts=["And a partridge in a pear tree.", "Two turtle doves", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"];
gifts=["And a partridge in a pear tree.", "Two turtle doves", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"];
{
{
Line 3,341: Line 4,061:
print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
)
)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
<pre>On the first day of Christmas, my true love gave to me:
Line 3,366: Line 4,086:
This should work with any modern Pascal implementation that has a '''string''' type, e.g. [[Free Pascal]].
This should work with any modern Pascal implementation that has a '''string''' type, e.g. [[Free Pascal]].


<lang pascal>program twelve_days(output);
<syntaxhighlight lang="pascal">program twelve_days(output);


const
const
Line 3,397: Line 4,117:
writeln
writeln
end
end
end.</lang>
end.</syntaxhighlight>
{{Out}}
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
<pre>On the first day of Christmas, my true love sent to me:
Line 3,424: Line 4,144:
Here's a version that works in ISO Standard Pascal, albeit with extraneous spaces in the output:
Here's a version that works in ISO Standard Pascal, albeit with extraneous spaces in the output:


<lang pascal>program twelve_days_iso(output);
<syntaxhighlight lang="pascal">program twelve_days_iso(output);


const
const
Line 3,456: Line 4,176:
writeln
writeln
end
end
end.</lang>
end.</syntaxhighlight>


{{Out}}
{{Out}}
Line 3,483: Line 4,203:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use v5.10;
<syntaxhighlight lang="perl">use v5.10;


my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };
my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };
Line 3,507: Line 4,227:
Three french hens
Three french hens
Two turtle doves
Two turtle doves
And a partridge in a pear tree.</lang>
And a partridge in a pear tree.</syntaxhighlight>
{{out}}
{{out}}
<pre>On the first day of Christmas,
<pre>On the first day of Christmas,
Line 3,536: Line 4,256:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">days</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"first"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"second"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"third"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fourth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fifth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"sixth"</span><span style="color: #0000FF;">,</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">days</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"first"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"second"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"third"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fourth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fifth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"sixth"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"seventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eighth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ninth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"tenth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eleventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"twelfth"</span><span style="color: #0000FF;">},</span>
<span style="color: #008000;">"seventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eighth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ninth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"tenth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eleventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"twelfth"</span><span style="color: #0000FF;">},</span>
Line 3,557: Line 4,277:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>include ..\Utilitys.pmt
<syntaxhighlight lang="phixmonti">include ..\Utilitys.pmt


( "A partridge in a pear tree."
( "A partridge in a pear tree."
Line 3,589: Line 4,309:
swap
swap
nl
nl
endfor</lang>
endfor</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
<syntaxhighlight lang="php">
<lang PHP>
<?php
<?php


Line 3,639: Line 4,359:


?>
?>
</syntaxhighlight>
</lang>


Or using recursion:
Or using recursion:


<lang PHP><?php
<syntaxhighlight lang="php"><?php


$gifts = array(
$gifts = array(
Line 3,677: Line 4,397:
twelve_days( array_reverse( $gifts, true ) );
twelve_days( array_reverse( $gifts, true ) );


</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre style="font-size:84%;height:55ex">
<pre style="font-size:84%;height:55ex">
Line 3,782: Line 4,502:
A partridge in a pear tree
A partridge in a pear tree
</pre>
</pre>

=={{header|Picat}}==
===List comprehension===
<syntaxhighlight lang="picat">go =>
Days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split(" "),
Gifts =
"A partridge in a pear tree.
Two turtle doves, and
Three french hens,
Four calling birds,
Five golden rings,
Six geese a-laying,
Seven swans a-swimming,
Eight maids a-milking,
Nine ladies dancing,
Ten lords a-leaping,
Eleven pipers piping,
Twelve drummers drumming,".split("\n"),

println([to_fstring("On the %s day of Christmas,\nMy true love gave to me:\n%w\n",
Day, slice(Gifts,1,D).reverse().join("\n")) : {Day,D} in zip(Days,1..length(Days))]
.join("\n")),
nl.</syntaxhighlight>

===Definite clause grammars (DCG)===
<syntaxhighlight lang="picat">go2 ?=>
lyrics(Ls,[]),
println(Ls.flatten),
nl.
go2 => true.

lyrics -->
{ Days = findall(D, $day(D,_,[])) },
stanzas(Days, []).

stanzas([], _) --> [].
stanzas([Day|Days], Prevs) -->
"On the ", [Day.to_string], " day of Christmas\n", % convert atom day to string
"My true love gave to me:\n",
day(Day),
previous_days(Prevs),
"\n\n",
stanzas(Days, [Day|Prevs]).

previous_days([]) --> [].
previous_days([D|Ds]) --> previous_days_(Ds, D).

previous_days_([], D) --> " and\n", day(D).
previous_days_([D|Ds], Prev) --> "\n",
day(Prev),
previous_days_(Ds, D).

day(first) --> "A partridge in a pear tree.".
day(second) --> "Two turtle doves".
day(third) --> "Three french hens".
day(fourth) --> "Four calling birds".
day(fifth) --> "Five golden rings".
day(sixth) --> "Six geese a-laying".
day(seventh) --> "Seven swans a-swimming".
day(eight) --> "Eight maids a-milking".
day(ninth) --> "Nine ladies dancing".
day(tenth) --> "Ten lords a-leaping".
day(eleventh) --> "Eleven pipers piping".
day(twelth) --> "Twelve drummers drumming".</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de days
<syntaxhighlight lang="picolisp">(de days
first second third fourth fifth sixth
first second third fourth fifth sixth
seventh eight ninth tenth eleventh twelfth )
seventh eight ninth tenth eleventh twelfth )
Line 3,812: Line 4,596:
(prinl) )
(prinl) )


(bye)</lang>
(bye)</syntaxhighlight>

=={{header|Pike}}==
<syntaxhighlight lang="pike">int main() {
array(string) days = ({"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"});
array(string) gifts = ({"A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"});

for (int i = 0; i < 12; i++) {
write("On the " + (string)days[i] + " day of Christmas\n");
write("My true love gave to me:\n");
for (int j = 0; j < i + 1; j++) {
write((string)gifts[i - j] + "\n");
}
if (i != 11) {
write("\n");
}
}
return 0;
}</syntaxhighlight>
{{out}}
<pre>On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.</pre>

=={{header|Pointless}}==
<syntaxhighlight lang="pointless">
output =
range(1, 12)
|> map(makeVerse)
|> join("\n\n")
|> print

days = {
1: "first",
2: "second",
3: "third",
4: "fourth",
5: "fifth",
6: "sixth",
7: "seventh",
8: "eighth",
9: "ninth",
10: "tenth",
11: "eleventh",
12: "twelfth"
}

verseFormat = """On the {} day of Christmas
My true love gave to me:
{}"""

makeVerse(n) =
format(verseFormat,
[getDefault(days, "", n),
makeGifts(n)])

gifts = [
"A partridge in a pear tree.",
"Two turtle doves and",
"Three french hens",
"Four calling birds",
"Five golden rings",
"Six geese a-laying",
"Seven swans a-swimming",
"Eight maids a-milking",
"Nine ladies dancing",
"Ten lords a-leaping",
"Eleven pipers piping",
"Twelve drummers drumming",
]

makeGifts(n) =
gifts
|> take(n)
|> reverse
|> join("\n")
</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang PowerShell>$days = @{
<syntaxhighlight lang="powershell">$days = @{
1 = "first";
1 = "first";
2 = "second";
2 = "second";
Line 3,853: Line 4,735:
}
}
""
""
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,882: Line 4,764:
A partridge in a pear tree
A partridge in a pear tree
</pre>
</pre>

=={{header|Prog8}}==
<syntaxhighlight lang="prog8">%zeropage basicsafe
%import textio

main {
str[12] ordinals = [ "first", "second", "third", "fourth",
"fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth" ]

str[12] gifts = [ "A partridge in a pear tree.",
"Two turtle doves and",
"Three French hens,",
"Four calling birds,",
"Five gold rings,",
"Six geese a-laying,",
"Seven swans a-swimming,",
"Eight maids a-milking,",
"Nine ladies dancing,",
"Ten lords a-leaping,",
"Eleven pipers piping,",
"Twelve drummers drumming," ]

sub print_gifts(ubyte day) {
ubyte i
txt.print("On the ")
txt.print(ordinals[day])
txt.print(" day of Christmas, my true love sent to me:")
txt.nl()
for i in day to 0 step -1 {
txt.print(gifts[i])
txt.nl()
}
}

sub start() {
ubyte day

txt.lowercase()
for day in 0 to 11 {
txt.nl()
print_gifts(day)
}
}
}</syntaxhighlight>

{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[ ... ]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.</pre>


=={{header|Prolog}}==
=={{header|Prolog}}==
<lang prolog>day(1, 'first').
<syntaxhighlight lang="prolog">day(1, 'first').
day(2, 'second').
day(2, 'second').
day(3, 'third').
day(3, 'third').
Line 3,925: Line 4,876:
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).


main :- writeLoop(12), halt.</lang>
main :- writeLoop(12), halt.</syntaxhighlight>


{{Out}}
{{Out}}
Line 3,935: Line 4,886:
A partridge in a pear tree.
A partridge in a pear tree.


[...]
[ ... ]


On the twelfth day of Christmas, my true love sent to me:
On the twelfth day of Christmas, my true love sent to me:
Line 3,952: Line 4,903:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>#TXT$ = "On the * day of Christmas, my true love sent to me:"
<syntaxhighlight lang="purebasic">#TXT$ = "On the * day of Christmas, my true love sent to me:"
days$ = ~"first\nsecond\nthird\nfourth\nfifth\nsixth\nseventh\neighth\nninth\ntenth\neleventh\ntwelfth\n"
days$ = ~"first\nsecond\nthird\nfourth\nfifth\nsixth\nseventh\neighth\nninth\ntenth\neleventh\ntwelfth\n"
gifts$= ~"Twelve drummers drumming,\nEleven pipers piping,\nTen lords a-leaping,\nNine ladies dancing,\n"+
gifts$= ~"Twelve drummers drumming,\nEleven pipers piping,\nTen lords a-leaping,\nNine ladies dancing,\n"+
Line 3,967: Line 4,918:
Next I
Next I
Input()
Input()
EndIf</lang>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre>On the first day of Christmas, my true love sent to me:
<pre>On the first day of Christmas, my true love sent to me:
Line 4,004: Line 4,955:


=={{header|Python}}==
=={{header|Python}}==
<lang python>gifts = '''\
<syntaxhighlight lang="python">gifts = '''\
A partridge in a pear tree.
A partridge in a pear tree.
Two turtle doves
Two turtle doves
Line 4,026: Line 4,977:
print(('\nOn the %s day of Christmas\nMy true love gave to me:\n' % day) +
print(('\nOn the %s day of Christmas\nMy true love gave to me:\n' % day) +
'\n'.join(g[:-1]) +
'\n'.join(g[:-1]) +
(' and\n' + g[-1] if n > 1 else g[-1].capitalize()))</lang>
(' and\n' + g[-1] if n > 1 else g[-1].capitalize()))</syntaxhighlight>


{{out}}
{{out}}
Line 4,070: Line 5,021:


=={{header|q}}==
=={{header|q}}==
<syntaxhighlight lang="q">
<lang q>
days:" "vs"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
DAYS:" "vs"first second third fourth fifth sixth",
" seventh eighth ninth tenth eleventh twelfth"


STANZA:( / final stanza
gifts:(
"On the twelfth day of Christmas";
"My true love gave to me:";
"Twelve drummers drumming";
"Twelve drummers drumming";
"Eleven pipers piping";
"Eleven pipers piping";
Line 4,088: Line 5,042:
"")
"")


-1 raze
verses:stanza 0 1,/:{(reverse x)+2+til each 2+x}til 12
lyric:raze .[;0 2;{"A",5_x}] verses{@[x;0;ssr[;"twelfth";y]]}'days
.[;0 2;"A",5_] / tweak one line
.[;(::;0);ssr[;"twelfth";];DAYS] / number the verses

STANZA 0 1,/:#\:[;til 15] -2 -til 12; / compose 12 verses
1 "\n"sv lyric; // print
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>On the first day of Christmas
<pre>On the first day of Christmas
Line 4,120: Line 5,074:
And a partridge in a pear tree.
And a partridge in a pear tree.
</pre>
</pre>
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/learn/pb/xmas-days/ The Q Playbook: The Twelve Days of Christmas – analysis]


=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ [ table
<syntaxhighlight lang="quackery"> [ [ table
$ "first" $ "second" $ "third" $ "fourth"
$ "first" $ "second" $ "third" $ "fourth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
Line 4,151: Line 5,104:
[ 12 times [ i^ verse ] ] is song ( --> )
[ 12 times [ i^ verse ] ] is song ( --> )
song</lang>
song</syntaxhighlight>


{{out}}
{{out}}
Line 4,184: Line 5,137:


=={{header|R}}==
=={{header|R}}==
<syntaxhighlight lang="r">
<lang R>
gifts <- c("A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming")
gifts <- c("A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming")
days <- c("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth")
days <- c("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth")
Line 4,192: Line 5,145:
cat("My true love gave to me:\n")
cat("My true love gave to me:\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,243: Line 5,196:
* British Variant: capitalises '''FIVE GO-OLD RINGS''' since it needs to be sung at top volume. If you want to change this back; the source is there. But I guarantee you won't have as much fun singing it.
* British Variant: capitalises '''FIVE GO-OLD RINGS''' since it needs to be sung at top volume. If you want to change this back; the source is there. But I guarantee you won't have as much fun singing it.


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(define (ordinal-text d)
(define (ordinal-text d)
(vector-ref
(vector-ref
Line 4,277: Line 5,230:
#:when (on-the... day)
#:when (on-the... day)
(prezzy-line (in-range day 0 -1)))
(prezzy-line (in-range day 0 -1)))
(printf "~a~a~%" (prezzy prezzy-line day) (line-end prezzy-line day)))</lang>
(printf "~a~a~%" (prezzy prezzy-line day) (line-end prezzy-line day)))</syntaxhighlight>


{{out}}
{{out}}
Line 4,342: Line 5,295:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my @days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;
<syntaxhighlight lang="raku" line>my @days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;


my @gifts = lines q:to/END/;
my @gifts = lines q:to/END/;
Line 4,368: Line 5,321:
nth($d);
nth($d);
say @gifts[$_] for $d ... 0;
say @gifts[$_] for $d ... 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
<pre>On the first day of Christmas, my true love gave to me:
Line 4,410: Line 5,363:
::* &nbsp; capitalized &nbsp; '''True Love''' &nbsp; as it (may) refer to a deity
::* &nbsp; capitalized &nbsp; '''True Love''' &nbsp; as it (may) refer to a deity
::* &nbsp; added indentation to make verses resemble song lyrics
::* &nbsp; added indentation to make verses resemble song lyrics
<lang rexx>/*REXX program displays the verses of the song: "The 12 days of Christmas". */
<syntaxhighlight lang="rexx">/*REXX program displays the verses of the song: "The 12 days of Christmas". */
ordD= 'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
ordD= 'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
pad= left('', 20) /*used for indenting the shown verses. */
pad= left('', 20) /*used for indenting the shown verses. */
Line 4,425: Line 5,378:
end /*j*/
end /*j*/
say /*add a blank line between the verses. */
say /*add a blank line between the verses. */
end /*day*/ /*stick a fork in it, we're all done. */</lang>
end /*day*/ /*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|:}}
{{out|output|:}}


Line 4,547: Line 5,500:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : The Twelve Days of Christmas
# Project : The Twelve Days of Christmas


Line 4,566: Line 5,519:
next
next


</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 4,696: Line 5,649:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>gifts = "A partridge in a pear tree
<syntaxhighlight lang="ruby">gifts = "A partridge in a pear tree
Two turtle doves and
Two turtle doves and
Three french hens
Three french hens
Line 4,717: Line 5,670:
puts gifts[0, i+1].reverse
puts gifts[0, i+1].reverse
puts
puts
end</lang>
end</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang Runbasic>gifts$ = "
<syntaxhighlight lang="runbasic">gifts$ = "
A partridge in a pear tree.,
A partridge in a pear tree.,
Two turtle doves,
Two turtle doves,
Line 4,745: Line 5,698:
print
print
next i
next i
</lang>Output:
</syntaxhighlight>Output:
<pre>On the first day of Christmas
<pre>On the first day of Christmas
My true love gave to me:
My true love gave to me:
Line 4,768: Line 5,721:
=={{header|Rust}}==
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=773d4af97e7c4b374574a3e1656b5029&version=stable&backtrace=0 Rust Playground]
[https://play.rust-lang.org/?gist=773d4af97e7c4b374574a3e1656b5029&version=stable&backtrace=0 Rust Playground]
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth"];
"ninth", "tenth", "eleventh", "twelfth"];


let gifts = ["A Patridge in a Pear Tree",
let gifts = ["A Partridge in a Pear Tree",
"Two Turtle Doves and",
"Two Turtle Doves and",
"Three French Hens",
"Three French Hens",
Line 4,794: Line 5,747:
println!()
println!()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>val gifts = Array(
<syntaxhighlight lang="scala">val gifts = Array(
"A partridge in a pear tree.",
"A partridge in a pear tree.",
"Two turtle doves and",
"Two turtle doves and",
Line 4,822: Line 5,775:


(0 until 12).map(giftsForDay andThen println)
(0 until 12).map(giftsForDay andThen println)
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 4,851: Line 5,804:
=={{header|Scheme}}==
=={{header|Scheme}}==
Without Common Lisp's <tt>format</tt>, we sadly have to hard-code the list of ordinals.
Without Common Lisp's <tt>format</tt>, we sadly have to hard-code the list of ordinals.
<syntaxhighlight lang="scheme">; Racket has this built in, but it's not standard
<lang scheme>(define take (lambda (n lst)
(define (take lst n)
(if (or (null? lst) (<= n 0))
(if (or (null? lst) (<= n 0))
'()
'()
(cons (car lst) (take (- n 1) (cdr lst))))))
(cons (car lst) (take (cdr lst) (- n 1)))))


(let
(let
Line 4,868: Line 5,822:


(do ((left days (cdr left))
(do ((left days (cdr left))
; No universal predefined (+ 1) function, sadly. Implementations
(day 1 (1+ day)))
; are divided between (add1) and (1+).
(day 1 (+ 1 day)))
((null? left) #t)
((null? left) #t)


Line 4,876: Line 5,832:
(newline)
(newline)


(do ((daily (reverse (take day gifts)) (cdr daily)))
(do ((daily (reverse (take gifts day)) (cdr daily)))
((null? daily) #t)
((null? daily) #t)


Line 4,883: Line 5,839:
(newline)))
(newline)))


(exit)</lang>
(exit)</syntaxhighlight>


{{Out}}
{{Out}}
Line 4,910: Line 5,866:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 4,935: Line 5,891:
end for;
end for;
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>


{{out}}
{{out}}
Line 4,974: Line 5,930:
=={{header|Self}}==
=={{header|Self}}==
Nicely factored:
Nicely factored:
<lang self>(|
<syntaxhighlight lang="self">(|
parent* = traits oddball.
parent* = traits oddball.


Line 5,005: Line 5,961:


|) value printLine
|) value printLine
</syntaxhighlight>
</lang>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>put [
<syntaxhighlight lang="sensetalk">put [
"partridge in a pear tree.",
"partridge in a pear tree.",
"turtle doves and",
"turtle doves and",
Line 5,035: Line 5,991:
end repeat
end repeat
put ""
put ""
end repeat</lang>
end repeat</syntaxhighlight>


{{out}}
{{out}}
Line 5,072: Line 6,028:
</pre>
</pre>


=={{header|SETL}}==
<syntaxhighlight lang="setl">program christmas;
ordinals := [
"first", "second", "third", "fourth", "fifth",
"sixth", "seventh", "eight", "ninth", "tenth",
"eleventh", "twelfth"
];
verses := [
"A partridge in a pear tree.",
"Two turtle doves and",
"Three french hens",
"Four calling birds",
"Five golden rings",
"Six geese a-laying",
"Seven swans a-swimming",
"Eight maids a-milking",
"Nine ladies dancing",
"Ten lords a-leaping",
"Eleven pipers piping",
"Twelve drummers drumming"
];
loop for i in [1..12] do
print("On the " + ordinals(i) + " day of Christmas,");
print("My true love gave to me");
loop for j in [i, i-1..1] do
print(verses(j));
end loop;
print;
end loop;
end program;</syntaxhighlight>
=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Raku}}
{{trans|Raku}}
<lang ruby>var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;
<syntaxhighlight lang="ruby">var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;


var gifts = <<'EOT'.lines;
var gifts = <<'EOT'.lines;
Line 5,102: Line 6,090:
say gifts[i];
say gifts[i];
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 5,143: Line 6,131:
=={{header|Simula}}==
=={{header|Simula}}==
{{works with|GNU Cim}}
{{works with|GNU Cim}}
<lang simula>Begin
<syntaxhighlight lang="simula">Begin
Text Array days(1:12), gifts(1:12);
Text Array days(1:12), gifts(1:12);
Integer day, gift;
Integer day, gift;
Line 5,183: Line 6,171:
End
End
End
End
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 5,211: Line 6,199:
=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
{{works with|GNU Smalltalk}}
<lang smalltalk>Object subclass: TwelveDays [
<syntaxhighlight lang="smalltalk">Object subclass: TwelveDays [
Ordinals := #('first' 'second' 'third' 'fourth' 'fifth' 'sixth'
Ordinals := #('first' 'second' 'third' 'fourth' 'fifth' 'sixth'
'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth').
'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth').
Line 5,237: Line 6,225:
1 to: 12 do: [:i |
1 to: 12 do: [:i |
Transcript show: (TwelveDays giftsFor: i); cr.
Transcript show: (TwelveDays giftsFor: i); cr.
].</lang>
].</syntaxhighlight>


{{Out}}
{{Out}}
Line 5,264: Line 6,252:


=={{header|Smart BASIC}}==
=={{header|Smart BASIC}}==
<lang smart BASIC>' by rbytes
<syntaxhighlight lang="smart basic">' by rbytes
dim d$(12),x$(15)!s=15
dim d$(12),x$(15)!s=15
for t=0 to 11!read d$(t)!next t
for t=0 to 11!read d$(t)!next t
Line 5,271: Line 6,259:
print x$(0)&d$(u)&x$(1)&chr$(10)&x$(2)
print x$(0)&d$(u)&x$(1)&chr$(10)&x$(2)
for t=s to 14!print x$(t)!next t
for t=s to 14!print x$(t)!next t
print!next u!data "first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","Twelfth","On the "," day of Christmas","My true love gave to me:","Twelve drummers drumming","Eleven pipers piping","Ten lords a-leaping","Nine ladies dancing","Eight maids a-milking","Seven swans a-swimming,","Six geese a-laying","Five golden rings","Four calling birds","Three french hens","Two turtle doves and","A partridge in a pear tree."</Lang>
print!next u!data "first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","Twelfth","On the "," day of Christmas","My true love gave to me:","Twelve drummers drumming","Eleven pipers piping","Ten lords a-leaping","Nine ladies dancing","Eight maids a-milking","Seven swans a-swimming,","Six geese a-laying","Five golden rings","Four calling birds","Three french hens","Two turtle doves and","A partridge in a pear tree."</syntaxhighlight>
<pre>On the first day of Christmas
<pre>On the first day of Christmas
My true love gave to me:
My true love gave to me:
Line 5,320: Line 6,308:
=={{header|Snobol}}==
=={{header|Snobol}}==
{{Works with|CSNOBOL4}}
{{Works with|CSNOBOL4}}
<lang snobol> DAYS = ARRAY('12')
<syntaxhighlight lang="snobol"> DAYS = ARRAY('12')
DAYS<1> = 'first'
DAYS<1> = 'first'
DAYS<2> = 'second'
DAYS<2> = 'second'
Line 5,359: Line 6,347:
NEXT OUTPUT = ''
NEXT OUTPUT = ''
DAY = DAY + 1 :(OUTER)
DAY = DAY + 1 :(OUTER)
END</lang>
END</syntaxhighlight>


{{Out}}
{{Out}}
Line 5,384: Line 6,372:
Two turtle doves and
Two turtle doves and
A partridge in a pear tree.</pre>
A partridge in a pear tree.</pre>

=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "twelve_days" )
@( description, "Write a program that outputs the lyrics of the " )
@( description, "Christmas carol The Twelve Days of Christmas. " )
@( see_also, "http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas" );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );

pragma restriction( no_external_commands );

procedure twelve_days is
type days is ( first, second, third, forth, fifth, sixth,seventh, eighth,
ninth, tenth, eleventh, twelfth );
gifts : array( first..twelfth ) of string := (
" A partridge in a pear-tree.",
" Two turtle doves",
" Three French hens",
" Four calling birds",
" Five golden rings",
" Six geese a-laying",
" Seven swans a-swimming",
" Eight maids a-milking",
" Nine ladies dancing",
" Ten lords a-leaping",
" Eleven pipers piping",
" Twelve drummers drumming"
);
begin
for day in first..twelfth loop
put( "On the " ) @ ( day ) @ ( " day of Christmas," );
new_line;
put_line( "My true love gave to me:" );
for subday in reverse first..day loop
put_line( gifts( subday ) );
end loop;
if day = first then
gifts( day ) := strings.replace_slice( gifts( day ), 2, 2, "And a" );
end if;
new_line;
end loop;
command_line.set_exit_status( 0 );
end twelve_days;
</syntaxhighlight>


=={{header|SQL}}==
=={{header|SQL}}==
Demonstration of Oracle 12c "with" clause enhancement.
Demonstration of Oracle 12c "with" clause enhancement.


<syntaxhighlight lang="sql">
<lang SQL>
with
with
function nl ( s in varchar2 )
function nl ( s in varchar2 )
Line 5,424: Line 6,458:
connect by level <= 12
connect by level <= 12
/
/
</syntaxhighlight>
</lang>
output:
output:
<pre>
<pre>
Line 5,453: Line 6,487:
=={{header|Swift}}==
=={{header|Swift}}==
{{works with|Swift|2.1}}
{{works with|Swift|2.1}}
<lang swift>let gifts = [ "partridge in a pear tree", "Two turtle doves",
<syntaxhighlight lang="swift">let gifts = [ "partridge in a pear tree", "Two turtle doves",
"Three French hens", "Four calling birds",
"Three French hens", "Four calling birds",
"Five gold rings", "Six geese a-laying",
"Five gold rings", "Six geese a-laying",
Line 5,481: Line 6,515:
for day in 1...12 {
for day in 1...12 {
print(giftsForDay(day))
print(giftsForDay(day))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 5,508: Line 6,542:


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<lang tailspin>
<syntaxhighlight lang="tailspin">
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
def gift: [
Line 5,540: Line 6,574:
' !
' !
\singVerse) -> !OUT::write
\singVerse) -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 5,572: Line 6,606:
</pre>
</pre>
=={{header|Terraform}}==
=={{header|Terraform}}==
<lang terraform>locals {
<syntaxhighlight lang="terraform">locals {
days = [ "first", "second", "third", "fourth", "fifth", "sixth",
days = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
Line 5,598: Line 6,632:
output "lyrics" {
output "lyrics" {
value = join("\n\n",[for t in data.template_file.days: t.rendered])
value = join("\n\n",[for t in data.template_file.days: t.rendered])
}</lang>
}</syntaxhighlight>




Line 5,633: Line 6,667:
=={{header|Tcl}}==
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
{{works with|Tcl|8.6}}
<lang tcl>set days {
<syntaxhighlight lang="tcl">set days {
first second third fourth fifth sixth
first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth
seventh eighth ninth tenth eleventh twelfth
Line 5,655: Line 6,689:
format "On the $day day of Christmas,\nMy true love gave to me:\n%s" \
format "On the $day day of Christmas,\nMy true love gave to me:\n%s" \
[join [lrange $gifts end-[incr n] end] \n]
[join [lrange $gifts end-[incr n] end] \n]
}] \n\n]</lang>
}] \n\n]</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:55ex;overflow:scroll">
<pre style="height:55ex;overflow:scroll">
Line 5,772: Line 6,806:
A partridge in a pear tree.
A partridge in a pear tree.
</pre>
</pre>

=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">Dim @n(12) : Dim @v(12) ' define both arrays

Proc _DataDays ' put data on the stack

For i=11 To 0 Step -1 ' read them in
@n(i) = Pop()
Next

Proc _DataGifts ' put data on the stack

For i=11 To 0 Step -1 ' read them in
@v(i) = Pop()
Next

For i=0 To 11 ' print all twelve verses
Print "On the ";Show(@n(i));" day of Christmas"
Print "My true love gave to me:"

For j=i To 0 Step -1 ' show list of gifts
Print Show(@v(j))
Next

Print ' next verse
Next
End

_DataDays
Push "first", "second", "third", "fourth"
Push "fifth", "sixth", "seventh", "eighth"
Push "ninth", "tenth", "eleventh", "twelfth"
Return

_DataGifts
Push "A partridge in a pear tree."
Push "Two turtle doves and"
Push "Three french hens"
Push "Four calling birds"
Push "Five golden rings"
Push "Six geese a-laying"
Push "Seven swans a-swimming"
Push "Eight maids a-milking"
Push "Nine ladies dancing"
Push "Ten lords a-leaping"
Push "Eleven pipers piping"
Push "Twelve drummers drumming"
Return</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
{{works with|Bourne Again SHell}}
{{works with|Korn Shell|93}}
{{works with|Korn Shell|93}}
<lang bash>#!/usr/bin/env bash
<syntaxhighlight lang="bash">#!/usr/bin/env bash
ordinals=(first second third fourth fifth sixth
ordinals=(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
seventh eighth ninth tenth eleventh twelfth)
Line 5,798: Line 6,880:
for (( day=0; day < 12; ++day )); do
for (( day=0; day < 12; ++day )); do
echo_gifts $day
echo_gifts $day
done</lang>
done</syntaxhighlight>


The above will also work in zsh if the index range is changed from 0..11 to 1..12.
The above will also work in zsh if the index range is changed from 0..11 to 1..12.
Line 5,805: Line 6,887:
(requires the '''seq''' command)
(requires the '''seq''' command)


<lang sh>#!/bin/sh
<syntaxhighlight lang="sh">#!/bin/sh
ordinal() {
ordinal() {
n=$1
n=$1
Line 5,837: Line 6,919:
for day in `seq 0 11`; do
for day in `seq 0 11`; do
echo_gifts $day
echo_gifts $day
done</lang>
done</syntaxhighlight>


{{Out}}
{{Out}}
Line 5,864: Line 6,946:


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Sub Main()
<syntaxhighlight lang="vb">Sub Main()
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim s, n
Dim s, n
Line 5,879: Line 6,961:
strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
Debug.Print Join(strReturn, vbCrLf)
Debug.Print Join(strReturn, vbCrLf)
End Sub</lang>
End Sub</syntaxhighlight>
{{out}}
{{out}}
<pre>On the first day of Christmas,
<pre>On the first day of Christmas,
Line 5,912: Line 6,994:


=={{header|VBScript}}==
=={{header|VBScript}}==
<lang vb>days = Array("first","second","third","fourth","fifth","sixth",_
<syntaxhighlight lang="vb">days = Array("first","second","third","fourth","fifth","sixth",_
"seventh","eight","ninth","tenth","eleventh","twelfth")
"seventh","eight","ninth","tenth","eleventh","twelfth")
Line 5,938: Line 7,020:
End If
End If
WScript.StdOut.WriteBlankLines(2)
WScript.StdOut.WriteBlankLines(2)
Next</lang>
Next</syntaxhighlight>




Line 5,944: Line 7,026:
This example uses calculated call targets.
This example uses calculated call targets.
Note that in the gift subroutines, the execution falls through all the following subroutines and returns only after the gift 1 routine.
Note that in the gift subroutines, the execution falls through all the following subroutines and returns only after the gift 1 routine.
<lang vedit>for (#1 = 1; #1 <= 12; #1++) {
<syntaxhighlight lang="vedit">for (#1 = 1; #1 <= 12; #1++) {
Num_Str(#1, 9, LEFT)
Num_Str(#1, 9, LEFT)
IT("On the ")
IT("On the ")
Line 5,979: Line 7,061:
:gift 2: IT("Two turtle doves, and") IN
:gift 2: IT("Two turtle doves, and") IN
:gift 1: IT("A partridge in a pear tree.") IN
:gift 1: IT("A partridge in a pear tree.") IN
return </lang>
return </syntaxhighlight>


=={{header|Vim Script}}==
=={{header|Vim Script}}==
{{trans|Raku}}
{{trans|Raku}}
<lang vimscript>
<syntaxhighlight lang="vimscript">
let b:days=["first", "second", "third", "fourth", "fifth", "sixth",
let b:days=["first", "second", "third", "fourth", "fifth", "sixth",
\ "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]
\ "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]
Line 6,019: Line 7,101:
endwhile
endwhile
let b:day = b:day + 1
let b:day = b:day + 1
endwhile</lang>
endwhile</syntaxhighlight>


{{Out}}
{{Out}}
Line 6,049: Line 7,131:
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)


<lang vbnet>Module Program
<syntaxhighlight lang="vbnet">Module Program
Sub Main()
Sub Main()
Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
Line 6,079: Line 7,161:
Next
Next
End Sub
End Sub
End Module</lang>
End Module</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>var days = [
<syntaxhighlight lang="wren">var days = [
"first", "second", "third", "fourth", "fifth", "sixth",
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
Line 6,099: Line 7,181:
for (j in i..0) System.print(gifts[j])
for (j in i..0) System.print(gifts[j])
System.print()
System.print()
}</lang>
}</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>int Day, Gift, D, G;
<syntaxhighlight lang="xpl0">int Day, Gift, D, G;
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Line 6,126: Line 7,208:
CrLf(0);
CrLf(0);
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 6,154: Line 7,236:
A partridge in a pear tree.
A partridge in a pear tree.
</pre>
</pre>

=={{header|Z80 Assembly}}==
You can copy-paste this into the WinAPE assembler and it will work. Run it with <code>CALL &8000</code> (remember that Shift+6 on the keyboard will give you & on Winape!) Press any key to advance to the next verse. This was repurposed from my entry to the Old Lady Swallowed A Fly task.


<syntaxhighlight lang="z80">waitChar equ &BB06 ;wait for a key press
PrintChar equ &BB5A ;print accumulator to screen

org &8000

ld ix,VerseTable
inc ix
inc ix
ld iy,SongLookup
ld b,12 ;12 verses total
outerloop_song:
push af ;new line
ld a,13
call PrintChar
ld a,10
call PrintChar
pop af
push bc
push ix
ld ix,VerseTable
ld a,(ix+0)
ld c,a ;get the low byte of verse ptr
ld a,(ix+1)
ld b,a ;get the high byte
pop ix
;bc = the memory location of Verse1
call loop_meta_PrintString
push ix
push iy
ld iy,Verse0
inc (IY+1)
inc (IY+1)
ld a,(IX+2)
ld (IY+7),a
ld a,(IX+3)
ld (IY+8),a
pop iy
pop ix
inc ix
inc ix
pop bc


call WaitChar ;wait for user to press any key before
;continuing so they have time to read it.


djnz outerloop_song

ReturnToBasic:
ret
loop_meta_PrintString:
ld a,(bc)
or a ;compare A to 0. 0 is the null terminator for verses.
ret z
cp 255 ;255 means "goto the verse specified after the 255"
jr z,GotoPreviousVerse
ld (smc_loop_meta_PrintString_alpha+2),a
;use self modifying code to point IY's offset to the correct
; song line, without changing IY itself.
inc a
ld (smc_loop_meta_PrintString_beta+2),a
smc_loop_meta_PrintString_alpha:
ld a,(iy+0) ;the "+0" gets clobbered with the desired lyric low byte
ld L,a
smc_loop_meta_PrintString_beta:
ld a,(iy+0) ;the "+0" gets clobbered with the desired lyric high byte
ld H,a
call PrintString ;now print the string in HL.
inc bc
jp loop_meta_PrintString
GotoPreviousVerse:
inc bc ;advance past &FF opcode
ld a,(bc) ;get low byte
ld e,a
inc bc ;advance to high byte
ld a,(bc)
ld d,a
push de
pop bc
jp loop_meta_PrintString
PrintString:
ld a,(hl)
or a
ret z
call PrintChar
inc hl
jr PrintString

;;;; data
VerseTable:
word Verse0
word Verse1
word Verse2
word Verse3
word Verse4
word Verse5
word Verse6
word Verse7
word Verse8
word Verse9
word Verse10
word Verse11
word Verse12
Verse0:
byte 2
byte 32 ;increment this by 2 after each verse.
byte 4,56,6,56
byte 255
word Verse1 ;look up next verse and write that here too.
;repeat until a hardcoded 12 verses are "sung"
Verse1:
byte 8,56,0
Verse2:
byte 10,56,255
word Verse1
Verse3:
byte 12,56,255
word Verse2
Verse4:
byte 14,56,255
word Verse3
Verse5:
byte 16,56,255
word Verse4
Verse6:
byte 18,56,255
word Verse5
Verse7:
byte 20,56,255
word Verse6
Verse8:
byte 22,56,255
word Verse7
Verse9:
byte 24,56,255
word Verse8
Verse10:
byte 26,56,255
word Verse9
Verse11:
byte 28,56,255
word Verse10
Verse12:
byte 30,56,255
word Verse11


SongLookup:
word null ;0
word Day_Part1 ;2
word Day_Part2 ;4
word Day_Part3 ;6
word Day1 ;8
word Day2 ;10
word Day3 ;12
word Day4 ;14
word Day5 ;16
word Day6 ;18
word Day7 ;20
word Day8 ;22
word Day9 ;24
word Day10 ;26
word Day11 ;28
word Day12 ;30
word First ;32
word Second ;34
word Third ;36
word Fourth ;38
word Fifth ;40
word Sixth ;42
word Seventh ;44
word Eighth ;46
word Ninth ;48
word Tenth ;50
word Eleventh ;52
word Twelfth ;54
word Song_NewLine ;56
null:
byte 0
Day_Part1:
byte "On the",0
Day_Part2:
byte "day of Christmas,",0
Day_Part3:
byte "my true love gave to me",0
Day1:
byte "a partridge in a pear tree.",0
Day2:
byte "two turtle doves, and",0
Day3:
byte "three french hens",0
Day4:
byte "four calling birds",0
Day5:
byte "five golden rings",0
Day6:
byte "six geese a-laying",0
Day7:
byte "seven swans a-swimming",0
Day8:
byte "eight maids a-milking",0
Day9:
byte "nine ladies dancing",0
Day10:
byte "ten lords a-leaping",0
Day11:
byte "eleven pipers piping",0
Day12:
byte "twelve drummers drumming",0
First:
byte " first ",0
Second:
byte " second ",0
Third:
byte " third ",0
Fourth:
byte " fourth ",0
Fifth:
byte " fifth ",0
Sixth:
byte " sixth ",0
Seventh:
byte " seventh ",0
Eighth:
byte " eighth ",0
Ninth:
byte " ninth ",0
Tenth:
byte " tenth ",0
Eleventh:
byte " eleventh ",0
Twelfth:
byte " twelfth ",0

Song_NewLine:
byte 13,10,0 ;control codes for a new line.</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Python}}
{{trans|Python}}
<lang zkl>gifts:=
<syntaxhighlight lang="zkl">gifts:=
#<<<
#<<<
"A beer, in a tree.; Two turtlenecks; Three french toast;
"A beer, in a tree.; Two turtlenecks; Three french toast;
Line 6,173: Line 7,514:
println("On the %s day of Christmas\nMy true love gave to me:\n".fmt(day),
println("On the %s day of Christmas\nMy true love gave to me:\n".fmt(day),
g[0,-1].concat("\n"), (n>1) and " and\n" or "", g[-1], "\n");
g[0,-1].concat("\n"), (n>1) and " and\n" or "", g[-1], "\n");
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}

Latest revision as of 11:47, 31 March 2024

Task
The Twelve Days of Christmas
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here.

(You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)


Other tasks related to string operations:
Metrics
Counting
Remove/replace
Anagrams/Derangements/shuffling
Find/Search/Determine
Formatting
Song lyrics/poems/Mad Libs/phrases
Tokenize
Sequences



11l

Translation of: Python
V gifts = |‘A partridge in a pear tree.
            Two turtle doves
            Three french hens
            Four calling birds
            Five golden rings
            Six geese a-laying
            Seven swans a-swimming
            Eight maids a-milking
            Nine ladies dancing
            Ten lords a-leaping
            Eleven pipers piping
            Twelve drummers drumming’.split("\n")

V days = ‘first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth’.split(‘ ’)

L(day) days
   V n = L.index + 1
   V g = reversed(gifts[0 .< n])
   print("\nOn the #. day of Christmas\nMy true love gave to me:\n".format(day)‘’g[0 .< (len)-1].join("\n")‘’(I n > 1 {" and\n"g.last} E g.last))

8080 Assembly

CR:	equ	13
LF:	equ	10
puts:	equ	9	; CP/M function to write a string to the console
bdos:	equ	5	; CP/M entry point
	org	100h
	mvi	e,0	; Start with first verse
	;;;	Print verse
verse:	lxi	h,onthe	; On the
	call	pstr
	lxi	h,ordtab
	call	ptabs	; Nth
	lxi 	h,doc
	call	pstr	; day of Christmas, my true love gave to me
	lxi	h,vrstab
	call	ptabs	; ...whatever stuff
	inr	e	; next verse
	mov	a,e
	cpi	12	; if at 12, stop
	jnz	verse	; otherwise, print another verse
	ret 
	;;;	Print the E'th string from the table under HL,
	;;;	preserving DE registers.
ptabs:	push 	d	; Save DE registers
	mvi	d,0	; Add E*2 to HL, looking up the pointer  
	dad	d
	dad	d
	mov	a,m	; Load low byte of pointer
	inx	h
	mov	h,m	; Load high byte of pointer
	mov	l,a
	xchg		; Store pointer in DE
	mvi	c,puts	; Print string in DE using CP/M
	call	bdos
	pop	d	; Restore registers
	ret
	;;;	Print the string under HL, preserving DE registers.
pstr:	push	d
	xchg
	mvi	c,puts
	call	bdos
	pop	d
	ret
ordtab:	dw	first,second,third,forth,fifth,sixth
	dw	_7th,eighth,ninth,tenth,_11th,_12th
vrstab:	dw	one,two,three,four,five,six,seven,eight
	dw	nine,ten,eleven,twelve
onthe:	db	'On the $'
first:	db	'first$'
second:	db	'second$'
third:	db	'third$'
forth:	db	'forth$'
fifth:	db	'fifth$'
sixth:	db	'sixth$'
_7th:	db	'seventh$'
eighth:	db	'eighth$'
ninth:	db	'ninth$'
tenth:	db	'tenth$'
_11th:	db	'eleventh$'
_12th:	db	'twelfth$'
doc:	db	' day of Christmas',CR,LF
	db	'My true love gave to me:',CR,LF,'$'
twelve:	db	'Twelve drummers drumming',CR,LF	
eleven:	db	'Eleven pipers piping',CR,LF
ten:	db	'Ten lords a-leaping',CR,LF
nine:	db	'Nine ladies dancing',CR,LF
eight:	db	'Eight maids a-milking',CR,LF
seven:	db	'Seven swans a-swimming',CR,LF
six:	db	'Six geese a-laying',CR,LF
five:	db	'Five golden rings',CR,LF
four: 	db	'Four calling birds',CR,LF
three:	db	'Three french hens',CR,LF
two:	db	'Two turtle doves and',CR,LF
one:	db	'A partridge in a pear tree.',CR,LF
	db	CR,LF,'$'

8086 Assembly

Translation of: 8080 Assembly
CR:	equ	10
LF:	equ	13
puts:	equ	9	; MS-DOS syscall to print string
	cpu	8086
	bits	16
	org	100h
section	.text
	xor	cx,cx		; Start with first verse
verse:	mov	dx,onthe	; On the...
	call	pstr
	mov	si,ord.tab	; Nth
	call	ptabs
	mov	dx,doc		; day of Christmas, my true love
	call	pstr		; gave to me...
	mov	si,vrs.tab	; the gifts
	call	ptabs
	inc	cx		; Next verse
	cmp	cx,12		; If not last verse,
	jb	verse		; then print next verse.
	ret
	;;;	Print the CX'th string from the table in [SI].
ptabs:	mov	bx,cx		; BX = CX*2
	shl	bx,1		; (Each entry is 2 bytes wide)
	mov	dx,[bx+si]	; Retrieve table entry
	;;;	Print the string in DX.
pstr:	mov	ah,puts		; Tell DOS to print the string
	int	21h
	ret
section	.data
onthe:	db	'On the $'
ord:
.n1:	db	'first$'
.n2:	db	'second$'
.n3:	db	'third$'
.n4:	db	'forth$'
.n5:	db	'fifth$'
.n6:	db	'sixth$'
.n7:	db	'seventh$'
.n8:	db	'eighth$'
.n9:	db	'ninth$'
.n10:	db	'tenth$'
.n11:	db	'eleventh$'
.n12:	db	'twelfth$'
.tab:	dw	.n1,.n2,.n3,.n4,.n5,.n6
	dw	.n7,.n8,.n9,.n10,.n11,.n12
doc:	db	' day of Christmas',CR,LF
	db	'My true love gave to me:',CR,LF,'$'
vrs:
.n12:	db	'Twelve drummers drumming',CR,LF
.n11:	db	'Eleven pipers piping',CR,LF
.n10:	db	'Ten lords a-leaping',CR,LF
.n9:	db	'Nine ladies dancing',CR,LF
.n8:	db	'Eight maids a-milking',CR,LF
.n7:	db	'Seven swans a-swimming',CR,LF
.n6:	db	'Six geese a-laying',CR,LF
.n5:	db	'Five golden rings',CR,LF
.n4: 	db	'Four calling birds',CR,LF
.n3:	db	'Three french hens',CR,LF
.n2:	db	'Two turtle doves and',CR,LF
.n1:	db	'A partridge in a pear tree.',CR,LF
	db	CR,LF,'$'
.tab:	dw	.n1,.n2,.n3,.n4,.n5,.n6
	dw	.n7,.n8,.n9,.n10,.n11,.n12

Action!

PROC Wait(BYTE frames)
  BYTE RTCLOK=$14
  frames==+RTCLOK
  WHILE frames#RTCLOK DO OD
RETURN

PROC Main()
  DEFINE PTR="CARD"
  PTR ARRAY num(12),obj(12)
  BYTE i,j

  num(0)="first" num(1)="second" num(2)="third"
  num(3)="fourth" num(4)="fifth" num(5)="sixth"
  num(6)="seventh" num(7)="eight" num(8)="ninth"
  num(9)="tenth" num(10)="eleventh" num(11)="Twelfth"

  obj(0)="And a partridge in a pear tree."
  obj(1)="Two turtle doves"
  obj(2)="Three french hens"
  obj(3)="Four calling birds"
  obj(4)="Five golden rings"
  obj(5)="Six geese a-laying"
  obj(6)="Seven swans a-swimming"
  obj(7)="Eight maids a-milking"
  obj(8)="Nine ladies dancing"
  obj(9)="Ten lords a-leaping"
  obj(10)="Eleven pipers piping"
  obj(11)="Twelve drummers drumming"

  FOR i=0 TO 11
  DO
    PrintF("On the %S day of Christmas,%E",num(i))
    PrintE("My true love gave to me:")
    IF i=0 THEN
      PrintE("A partridge in a pear tree.")
    ELSE
      j=i+1
      WHILE j>0
      DO
        j==-1
        PrintE(obj(j))
      OD
    FI
    PutE()
    Wait(50)
  OD
RETURN
Output:

Screenshot from Atari 8-bit computer

On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves
And a partridge in a pear tree.

...

On the Twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.

ActionScript

This program outputs the lyrics to a TextField object. The text field can be scrolled using the mouse wheel (Windows only) or by using the up/down arrow keys on the keyboard.

Works with: Flash Player version 10
Works with: AIR version 1.5

(Although the code can work in Flash Player 9 by replacing the Vectors with Arrays)

package {
    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.ui.Keyboard;
    
    public class TwelveDaysOfChristmas extends Sprite {
        
        private var _textArea:TextField = new TextField();
        
        public function TwelveDaysOfChristmas() {
            if ( stage ) _init();
            else addEventListener(Event.ADDED_TO_STAGE, _init);
        }
        
        private function _init(e:Event = null):void {
            
            removeEventListener(Event.ADDED_TO_STAGE, _init);
            
            _textArea = new TextField();
            _textArea.x = 10;
            _textArea.y = 10;
            _textArea.autoSize = TextFieldAutoSize.LEFT;
            _textArea.wordWrap = true;
            _textArea.width = stage.stageWidth - 20;
            _textArea.height = stage.stageHeight - 10;
            _textArea.multiline = true;
            
            var format:TextFormat = new TextFormat();
            format.size = 14;
            _textArea.defaultTextFormat = format;
            
            var verses:Vector.<String> = new Vector.<String>(12, true);
            var lines:Vector.<String>;
            
            var days:Vector.<String> = new Vector.<String>(12, true);
            var gifts:Vector.<String> = new Vector.<String>(12, true);
            
            days[0] = 'first';
            days[1] = 'second';
            days[2] = 'third';
            days[3] = 'fourth';
            days[4] = 'fifth';
            days[5] = 'sixth';
            days[6] = 'seventh';
            days[7] = 'eighth';
            days[8] = 'ninth';
            days[9] = 'tenth';
            days[10] = 'eleventh';
            days[11] = 'twelfth';
            
            gifts[0] = 'A partridge in a pear tree';
            gifts[1] = 'Two turtle doves';
            gifts[2] = 'Three french hens';
            gifts[3] = 'Four calling birds';
            gifts[4] = 'Five golden rings';
            gifts[5] = 'Six geese a-laying';
            gifts[6] = 'Seven swans a-swimming';
            gifts[7] = 'Eight maids a-milking';
            gifts[8] = 'Nine ladies dancing';
            gifts[9] = 'Ten lords a-leaping';
            gifts[10] = 'Eleven pipers piping';
            gifts[11] = 'Twelve drummers drumming';
            
            var i:uint, j:uint, k:uint, line:String;
            
            for ( i = 0; i < 12; i++ ) {
                
                lines = new Vector.<String>(i + 2, true);
                lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
                
                j = i + 1;
                k = 0;
                while ( j-- > 0 )
                    lines[++k] = gifts[j];
                
                verses[i] = lines.join('\n');
                
                if ( i == 0 )
                    gifts[0] = 'And a partridge in a pear tree';
                
            }
            
            var song:String = verses.join('\n\n');
            _textArea.text = song;
            addChild(_textArea);
            
            _textArea.addEventListener(MouseEvent.MOUSE_WHEEL, _onMouseWheel);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);
            
        }
        
        private function _onKeyDown(e:KeyboardEvent):void {
            if ( e.keyCode == Keyboard.DOWN )
                _textArea.y -= 40;
            else if ( e.keyCode == Keyboard.UP )
                _textArea.y += 40;
        }
        
        private function _onMouseWheel(e:MouseEvent):void {
            _textArea.y += 20 * e.delta;
        }
        
    }
    
}

Ada

with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Twelve_Days_Of_Christmas is
   type Days is (First, Second, Third, Fourth, Fifth, Sixth,
		 Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth);
   
   package E_IO is new Ada.Text_IO.Enumeration_IO(Days);
   use E_IO;
   
   Gifts : array (Days) of Unbounded_String :=
     (To_Unbounded_String(" A partridge in a pear-tree."),
      To_Unbounded_String(" Two turtle doves"),
      To_Unbounded_String(" Three French hens"),
      To_Unbounded_String(" Four calling birds"),
      To_Unbounded_String(" Five golden rings"),
      To_Unbounded_String(" Six geese a-laying"),
      To_Unbounded_String(" Seven swans a-swimming"),
      To_Unbounded_String(" Eight maids a-milking"),
      To_Unbounded_String(" Nine ladies dancing"),
      To_Unbounded_String(" Ten lords a-leaping"),
      To_Unbounded_String(" Eleven pipers piping"),
      To_Unbounded_String(" Twelve drummers drumming"));
begin
   for Day in Days loop
      Put("On the "); Put(Day, Set => Lower_Case); Put(" day of Christmas,");
      New_Line; Put_Line("My true love gave to me:");
      for D in reverse Days'First..Day loop
	 Put_Line(To_String(Gifts(D)));
      end loop;
      if Day = First then
	 Replace_Slice(Gifts(Day), 2, 2, "And a");
      end if;
      New_Line;
   end loop;
end Twelve_Days_Of_Christmas;

ALGOL 68

Works with: ALGOL 68 Genie
BEGIN
  []STRING labels = ("first", "second", "third",    "fourth",
                     "fifth", "sixth",  "seventh",  "eighth",
                     "ninth", "tenth",  "eleventh", "twelfth");

  []STRING gifts = ("A partridge in a pear tree.",
                    "Two turtle doves, and",
                    "Three French hens,",
                    "Four calling birds,",
                    "Five gold rings,",
                    "Six geese a-laying,",
                    "Seven swans a-swimming,",
                    "Eight maids a-milking,",
                    "Nine ladies dancing,",
                    "Ten lords a-leaping,",
                    "Eleven pipers piping,",
                    "Twelve drummers drumming,");
  FOR day TO 12 DO
    print(("On the ", labels[day],
           " day of Christmas, my true love sent to me:", newline));
    FOR gift FROM day BY -1 TO 1 DO
      print((gifts[gift], newline))
    OD;
    print(newline)
  OD
END
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.

APL

Works with: Dyalog APL
Translation of: Forth
ord  {   'first' 'second' 'third' 'fourth' 'fifth' 'sixth' 'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth' }

gift  {   'A partridge in a pear tree.' 'Two turtle doves, and' 'Three French hens,' 'Four calling birds,' 'Five gold rings,' 'Six geese a-laying,' 'Seven swans a-swimming,' 'Eight maids a-milking,' 'Nine ladies dancing,' 'Ten lords a-leaping,' 'Eleven pipers piping,' 'Twelve drummers drumming,' }

day  {   (⎕ucs 10),'On the',(ord ),'day of Christmas, my true love sent to me:'  {   gift  } ¨ ⌽⍳ }

day ¨ 12
Output:
On the first day of Christmas, my true love sent to me:
 A partridge in a pear tree. 


On the second day of Christmas, my true love sent to me:
 Two turtle doves, and 
 A partridge in a pear tree. 


On the third day of Christmas, my true love sent to me:
 Three French hens, 
 Two turtle doves, and 
 A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
 Twelve drummers drumming, 
 Eleven pipers piping, 
 Ten lords a-leaping, 
 Nine ladies dancing, 
 Eight maids a-milking, 
 Seven swans a-swimming, 
 Six geese a-laying, 
 Five gold rings, 
 Four calling birds, 
 Three French hens, 
 Two turtle doves, and 
 A partridge in a pear tree.

AppleScript

Iterative

set gifts to {"A partridge in a pear tree.", "Two turtle doves, and", ¬
	"Three French hens,", "Four calling birds,", ¬
	"Five gold rings,", "Six geese a-laying,", ¬
	"Seven swans a-swimming,", "Eight maids a-milking,", ¬
	"Nine ladies dancing,", "Ten lords a-leaping,", ¬
	"Eleven pipers piping,", "Twelve drummers drumming"}

set labels to {"first", "second", "third", "fourth", "fifth", "sixth", ¬
	"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}

repeat with day from 1 to 12
	log "On the " & item day of labels & " day of Christmas, my true love sent to me:"
	repeat with gift from day to 1 by -1
		log item gift of gifts
	end repeat
	log ""
end repeat
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.


Functional composition

Drawing on some functional primitives, and post-Yosemite AppleScript's ability to import Foundation classes:

use framework "Foundation"

property pstrGifts : "A partridge in a pear tree, Two turtle doves, Three French hens, " & ¬
    "Four calling birds, Five golden rings, Six geese a-laying, " & ¬
    "Seven swans a-swimming, Eight maids a-milking, Nine ladies dancing, " & ¬
    "Ten lords a-leaping, Eleven pipers piping, Twelve drummers drumming"

property pstrOrdinals : "first, second, third, fourth, fifth, " & ¬
    "sixth, seventh, eighth, ninth, tenth, eleventh, twelfth"

-- DAYS OF XMAS ------------------------------------------------------------

-- daysOfXmas :: () -> String
on daysOfXmas()
    
    -- csv :: String -> [String]
    script csv
        on |λ|(str)
            splitOn(", ", str)
        end |λ|
    end script
    
    set {gifts, ordinals} to map(csv, [pstrGifts, pstrOrdinals])
    
    -- verseOfTheDay :: Int -> String
    script verseOfTheDay
        
        -- dayGift :: Int -> String
        script dayGift
            on |λ|(n, i)
                set strGift to item n of gifts
                if n = 1 then
                    set strFirst to strGift & " !"
                    if i is not 1 then
                        "And " & toLower(text 1 of strFirst) & text 2 thru -1 of strFirst
                    else
                        strFirst
                    end if
                else if n = 5 then
                    toUpper(strGift)
                else
                    strGift
                end if
            end |λ|
        end script
        
        on |λ|(intDay)
            "On the " & item intDay of ordinals & " day of Xmas, my true love gave to me ..." & ¬
                linefeed & intercalate("," & linefeed, ¬
                map(dayGift, enumFromTo(intDay, 1)))
            
        end |λ|
    end script
    
    intercalate(linefeed & linefeed, ¬
        map(verseOfTheDay, enumFromTo(1, length of ordinals)))
    
end daysOfXmas

-- TEST ---------------------------------------------------------------------
on run
    
    daysOfXmas()
    
end run


-- GENERIC FUNCTIONS --------------------------------------------------------

-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
    if m > n then
        set d to -1
    else
        set d to 1
    end if
    set lst to {}
    repeat with i from m to n by d
        set end of lst to i
    end repeat
    return lst
end enumFromTo

-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
    set {dlm, my text item delimiters} to {my text item delimiters, strText}
    set strJoined to lstText as text
    set my text item delimiters to dlm
    return strJoined
end intercalate

-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
    tell mReturn(f)
        set lng to length of xs
        set lst to {}
        repeat with i from 1 to lng
            set end of lst to |λ|(item i of xs, i, xs)
        end repeat
        return lst
    end tell
end map

-- Lift 2nd class handler function into 1st class script wrapper 
-- mReturn :: Handler -> Script
on mReturn(f)
    if class of f is script then
        f
    else
        script
            property |λ| : f
        end script
    end if
end mReturn

-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
    set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
    set lstParts to text items of strMain
    set my text item delimiters to dlm
    return lstParts
end splitOn

-- toLower :: String -> String
on toLower(str)
    set ca to current application
    ((ca's NSString's stringWithString:(str))'s ¬
        lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower

-- toUpper :: String -> String
on toUpper(str)
    set ca to current application
    ((ca's NSString's stringWithString:(str))'s ¬
        uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper
Output:
On the first day of Xmas, my true love gave to me ...
A partridge in a pear tree !

On the second day of Xmas, my true love gave to me ...
Two turtle doves,
And a partridge in a pear tree !

...

On the twelfth day of Xmas, my true love gave to me ...
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree !

Arturo

gifts: [
    "A partridge in a pear tree."
    "Two turtle doves"
    "Three french hens"
    "Four calling birds"
    "Five golden rings"
    "Six geese a-laying"
    "Seven swans a-swimming"
    "Eight maids a-milking"
    "Nine ladies dancing"
    "Ten lords a-leaping"
    "Eleven pipers piping"
    "Twelve drummers drumming"
]

days: ["first" "second" "third" "fourth" "fifth" "sixth"
       "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth"]

loop.with:'n days 'day [
    g: reverse slice gifts 0 n
    print ~"On the |day| day of Christmas\n" ++
          "My true love gave to me:\n" ++
          (join.with:"\n" chop g) ++
          (n>0)? -> " and \n" ++ last g
                 -> capitalize last g
    print ""
]
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and 
A partridge in a pear tree.

On the third day of Christmas
My true love gave to me:
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the fourth day of Christmas
My true love gave to me:
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the fifth day of Christmas
My true love gave to me:
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the sixth day of Christmas
My true love gave to me:
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the seventh day of Christmas
My true love gave to me:
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the eighth day of Christmas
My true love gave to me:
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the ninth day of Christmas
My true love gave to me:
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the tenth day of Christmas
My true love gave to me:
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the eleventh day of Christmas
My true love gave to me:
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and 
A partridge in a pear tree.

AutoHotkey

nth := ["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]
lines := ["A partridge in a pear tree."
		,"Two turtle doves and"
		,"Three french hens"
		,"Four calling birds"
		,"Five golden rings"
		,"Six geese a-laying"
		,"Seven swans a-swimming"
		,"Eight maids a-milking"
		,"Nine ladies dancing"
		,"Ten lords a-leaping"
		,"Eleven pipers piping"
		,"Twelve drummers drumming"]

full:="", mid:=""
loop % lines.MaxIndex()
{
	top:="On the " . nth[A_Index] . " day of Christmas,`nMy true love gave to me:"
	mid:= lines[A_Index] . "`n" . mid
	full:= full . top . "`n" . mid . ((A_Index<lines.MaxIndex())?"`n":"")
}
MsgBox % full

AWK

# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
BEGIN {
    gifts[++i] = "a partridge in a pear tree."
    gifts[++i] = "two turtle doves, and"
    gifts[++i] = "three french hens,"
    gifts[++i] = "four calling birds,"
    gifts[++i] = "five golden rings,"
    gifts[++i] = "six geese a-laying,"
    gifts[++i] = "seven swans a-swimming,"
    gifts[++i] = "eight maids a-milking,"
    gifts[++i] = "nine ladies dancing,"
    gifts[++i] = "ten lords a-leaping,"
    gifts[++i] = "eleven pipers piping,"
    gifts[++i] = "twelve drummers drumming,"
    split("first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth",days_arr," ")
    for (i=1; i<=12; i++) {
      printf("On the %s day of Christmas,\n",days_arr[i])
      print("my true love gave to me:")
      for (j=i; j>0; j--) {
        printf("%s\n",gifts[j])
      }
      print("")
    }
    exit(0)
}
Output:
On the first day of Christmas,
my true love gave to me:
a partridge in a pear tree.

On the second day of Christmas,
my true love gave to me:
two turtle doves, and
a partridge in a pear tree.

...

On the twelfth day of Christmas,
my true love gave to me:
twelve drummers drumming,
eleven pipers piping,
ten lords a-leaping,
nine ladies dancing,
eight maids a-milking,
seven swans a-swimming,
six geese a-laying,
five golden rings,
four calling birds,
three french hens,
two turtle doves, and
a partridge in a pear tree.

Batch File

:: The Twelve Days of Christmas
:: Batch File Implementation

@echo off

::Pseudo-array for Days
set "day1=First"
set "day2=Second"
set "day3=Third"
set "day4=Fourth"
set "day5=Fifth"
set "day6=Sixth"
set "day7=Seventh"
set "day8=Eighth"
set "day9=Nineth"
set "day10=Tenth"
set "day11=Eleventh"
set "day12=Twelveth"

::Pseudo-array for Gifts
set "gift12=Twelve drummers drumming"
set "gift11=Eleven pipers piping"
set "gift10=Ten loards a-leaping"
set "gift9=Nine ladies dancing"
set "gift8=Eight maids a-milking"
set "gift7=Seven swans a-swimming"
set "gift6=Six geese a-laying"
set "gift5=Five golden rings"
set "gift4=Four calling birds"
set "gift3=Three french hens"
set "gift2=Two turtle doves"
set "gift1=A partridge in a pear tree"

::Display It!
setlocal enabledelayedexpansion
for /l %%i in (1,1,12) do (
	echo On the !day%%i! day of Christmas
        echo My true love gave to me:

	for /l %%j in (%%i,-1,1) do (
		if %%j equ 1 (
			if %%i neq 1 <nul set /p ".=And "
			echo !gift1!.
		) else (
			echo !gift%%j!,
		)
	)
	echo(
)
exit /b

BASIC

10 DEFINT I,J: DEFSTR N,V: DIM N(12),V(12)
20 FOR I=1 TO 12: READ N(I): NEXT
30 FOR I=1 TO 12: READ V(I): NEXT
40 FOR I=1 TO 12
50 PRINT "On the ";N(I);" day of Christmas"
60 PRINT "My true love gave to me:"
70 FOR J=I TO 1 STEP -1: PRINT V(J): NEXT
75 PRINT
80 NEXT
90 END
100 DATA first,second,third,fourth,fifth,sixth
110 DATA seventh,eighth,ninth,tenth,eleventh,twelfth
120 DATA "A partridge in a pear tree."
130 DATA "Two turtle doves and"
140 DATA "Three french hens"
150 DATA "Four calling birds"
160 DATA "Five golden rings"
170 DATA "Six geese a-laying"
180 DATA "Seven swans a-swimming"
190 DATA "Eight maids a-milking"
200 DATA "Nine ladies dancing"
210 DATA "Ten lords a-leaping"
220 DATA "Eleven pipers piping"
230 DATA "Twelve drummers drumming"

Applesoft BASIC

The GW-BASIC solution works without any changes.

BASIC256

dim dia$ = {"first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"}

dim gift$ = {"A partridge in a pear tree.","Two turtle doves and","Three french hens","Four calling birds","Five golden rings","Six geese a-laying","Seven swans a-swimming","Eight maids a-milking","Nine ladies dancing","Ten lords a-leaping","Eleven pipers piping","Twelve drummers drumming"}

for i = 0 to 11
    print "On the "; dia$[i]; " dia of Christmas,"
    print "My true love gave to me:"
    for j = i to 1 step -1
        print gift$[j]
    next j
    print
next i

Chipmunk Basic

Works with: Chipmunk Basic version 3.6.4

The GW-BASIC solution works without any changes.

Commodore BASIC

Similar to other 8-bit BASICs shown here. This adds a delay and grammar adjustments. Color coding specific to Commodore 64/128.

1 rem rosetta code
2 rem twelve days of christmas
5 print chr$(14):poke 53280,13:poke 53281,1
10 dim a$(12),ex$(12):a=1
15 for i=1 to 12:read a$(i),ex$(i):next i
20 for c=1 to 12
25   print chr$(147):print chr$(30);"     The Twelve Days of Christmas":print
30   print chr$(28);" On the ";a$(c);" day of Christmas":gosub 200
35   print " my true love gave to me: ":print:gosub 200
40   for bc=c to 1 step -1
45   print tab(4);
50     if c=1 then print "A ";
55     if c>1 and bc=1 then print "And a ";
60     print ex$(bc);
65     if bc=1 or bc=5 then print "!":gosub 200:gosub 200:goto 75
70     print ","
75     gosub 200
80   next bc
85   rem pause for verse change
90   print:for t=1 to 500:next t
95 next c
100 end

200 for t=1 to 750:next t:return:rem generic delay

1000 rem lyrics
1010 data "first","partridge in a pear tree"
1020 data "second","Two turtle doves"
1030 data "third","Three french hens"
1040 data "fourth","Four calling birds"
1050 data "fifth","Five golden rings"
1060 data "sixth","Six geese a-laying"
1070 data "seventh","Seven swans a-swimming"
1080 data "eighth","Eight maids a-milking"
1090 data "ninth","Nine ladies dancing"
1100 data "tenth","Ten lords a-leaping"
1110 data "eleventh","Eleven pipers piping"
1120 data "twelfth","Twelve drummers drumming"

GW-BASIC

Works with: PC-BASIC version any
Works with: BASICA
Works with: Applesoft BASIC
Works with: Chipmunk Basic
Works with: QBasic
Works with: MSX BASIC
Works with: Quite BASIC
100 CLS : REM  100 HOME for Applesoft BASIC
110 DIM D$(12)
120 DIM G$(12)
130 FOR I = 1 TO 12 : READ D$(I) : NEXT I
140 FOR I = 1 TO 12 : READ G$(I) : NEXT I
150 FOR I = 1 TO 12
160   PRINT "On the ";D$(I);" day of Christmas,"
170   PRINT "My true love gave to me:"
180   FOR J = I TO 1 STEP -1 : PRINT G$(J) : NEXT J
190   PRINT
200 NEXT I
210 END
220 DATA "first","second","third","fourth","fifth","sixth"
230 DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
240 DATA "A partridge in a pear tree."
250 DATA "Two turtle doves and"
260 DATA "Three french hens"
270 DATA "Four calling birds"
280 DATA "Five golden rings"
290 DATA "Six geese a-laying"
300 DATA "Seven swans a-swimming"
310 DATA "Eight maids a-milking"
320 DATA "Nine ladies dancing"
330 DATA "Ten lords a-leaping"
340 DATA "Eleven pipers piping"
350 DATA "Twelve drummers drumming"

MSX Basic

Works with: MSX BASIC version any

The GW-BASIC solution works without any changes.

Quite BASIC

The GW-BASIC solution works without any changes.

True BASIC

Works with: QBasic version 1.1
Works with: QuickBasic version 4.5
DATA "first","second","third","fourth","fifth","sixth"
DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
DATA "A partridge in a pear tree."
DATA "Two turtle doves and"
DATA "Three french hens"
DATA "Four calling birds"
DATA "Five golden rings"
DATA "Six geese a-laying"
DATA "Seven swans a-swimming"
DATA "Eight maids a-milking"
DATA "Nine ladies dancing"
DATA "Ten lords a-leaping"
DATA "Eleven pipers piping"
DATA "Twelve drummers drumming"

DIM day$(12), gift$(12)
FOR i = 1 TO 12
    READ day$(i)
NEXT i
FOR i = 1 TO 12
    READ gift$(i)
NEXT i

FOR i = 1 TO 12
    PRINT "On the "; day$(i); " day of Christmas,"
    PRINT "My true love gave TO me:"
    FOR j = i TO 1 STEP -1
        PRINT gift$(j)
    NEXT j
    PRINT
NEXT i
END

XBasic

Works with: Windows XBasic
PROGRAM	"The Twelve Days of Christmas"
VERSION	"0.0000"

DECLARE FUNCTION  Entry ()

FUNCTION  Entry ()
  DIM day$[11]
  day$[0] = "first"
  day$[1] = "second"
  day$[2] = "third"
  day$[3] = "fourth"
  day$[4] = "fifth"
  day$[5] = "sixth"
  day$[6] = "seventh"
  day$[7] = "eighth"
  day$[8] = "ninth"
  day$[9] = "tenth"
  day$[10] = "eleventh"
  day$[11] = "twelfth"

  DIM gift$[11]
  gift$[0] = "A partridge in a pear tree."
  gift$[1] = "Two turtle doves and"
  gift$[2] = "Three french hens"
  gift$[3] = "Four calling birds"
  gift$[4] = "Five golden rings"
  gift$[5] = "Six geese a-laying"
  gift$[6] = "Seven swans a-swimming"
  gift$[7] = "Eight maids a-milking"
  gift$[8] = "Nine ladies dancing"
  gift$[9] = "Ten lords a-leaping"
  gift$[10] = "Eleven pipers piping"
  gift$[11] = "Twelve drummers drumming"

  FOR i = 0 TO 11
    PRINT "On the "; day$[i]; " day of Christmas,"
    PRINT "My true love gave to me:"
    FOR J = i TO 0 STEP -1
      PRINT gift$[J]
    NEXT J
    PRINT
  NEXT i
END FUNCTION
END PROGRAM

Yabasic

dim day$(12), gift$(12)
for i = 1 to 12: read day$(i): next i
for i = 1 to 12: read gift$(i): next i
for i = 1 to 12
    print "On the ", day$(i), " day of Christmas,"
    print "My true love gave to me:"
    for j = i to 1 step -1: print gift$(j): next j
    print
next i
end

data "first","second","third","fourth","fifth","sixth"
data "seventh","eighth","ninth","tenth","eleventh","twelfth"
data "A partridge in a pear tree."
data "Two turtle doves and"
data "Three french hens"
data "Four calling birds"
data "Five golden rings"
data "Six geese a-laying"
data "Seven swans a-swimming"
data "Eight maids a-milking"
data "Nine ladies dancing"
data "Ten lords a-leaping"
data "Eleven pipers piping"
data "Twelve drummers drumming"

BCPL

get "libhdr"

let ordinal(n) =
    n=1 -> "first",     n=2 -> "second",    n=3 -> "third",
    n=4 -> "fourth",    n=5 -> "fifth",     n=6 -> "sixth",
    n=7 -> "seventh",   n=8 -> "eighth",    n=9 -> "ninth",
    n=10 -> "tenth",    n=11 -> "eleventh", n=12 -> "twelfth",
    valof finish

let gift(n) = 
    n=1 -> "A partridge in a pear tree.",
    n=2 -> "Two turtle doves, and",
    n=3 -> "Three french hens,",
    n=4 -> "Four calling birds,",
    n=5 -> "Five golden rings,",
    n=6 -> "Six geese a-laying,",
    n=7 -> "Seven swans a-swimming,",
    n=8 -> "Eight maids a-milking,",
    n=9 -> "Nine ladies dancing,",
    n=10 -> "Ten lords a-leaping,",
    n=11 -> "Eleven pipers piping,",
    n=12 -> "Twelve drummers drumming,",
    valof finish
    
let verse(n) be
$(  writef("On the %S day of Christmas,*N", ordinal(n))
    writes("My true love gave to me:*N")
    for i=n to 1 by -1 do writef("%S*N", gift(i))
    wrch('*N')
$)

let start() be for n=1 to 12 do verse(n)

Befunge

This is essentially the same algorithm as Old lady swallowed a fly - just a different set of phrases and a simpler song pattern.

0246*+00p20#v_:#`2#g+#0:#0<>\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#11#\0#50#< g2-:00p4v   >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
             ^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$<
(On the ?|A partridge in a pear tree.||&first% andL day of Christmas,|My true l
ove gave to me:2|Two turtle doves'second3|Three french hens&third4|Four calling
 birds'fourth3|Five golden rings&fifth4|Six geese a-laying&sixth8|Seven swans a
-swimming(seventh7|Eight maids a-milking'eighth5|Nine ladies dancing&ninth5|Ten
 lords a-leaping&tenth6|Eleven pipers piping)eleventh:|Twelve drummers drumming
(twelfth

Bracmat

(     first
      second
      third
      fourth
      fifth
      sixth
      seventh
      eighth
      ninth
      tenth
      eleventh
      twelveth
  : ?days
&     "A partridge in a pear tree."
      "Two turtle doves and"
      "Three french hens,"
      "Four calling birds,"
      "Five golden rings,"
      "Six geese a-laying,"
      "Seven swans a-swimming,"
      "Eight maids a-milking,"
      "Nine ladies dancing,"
      "Ten lords a-leaping,"
      "Eleven pipers piping,"
      "Twelve drummers drumming,"
  : ?gifts
& :?given
&   whl
  ' ( !gifts:%?gift ?gifts
    & !gift \n !given:?given
    & !days:%?day ?days
    &   out
      $ ( str
        $ ("\nOn the " !day " day of Christmas my true love gave to me:
" !given)
        )
    )
);

C

#include<stdio.h>
 
int main()
{
    int i,j;
 
    char days[12][10] = 
    {
        "First",
        "Second",
        "Third",
        "Fourth",
        "Fifth",
        "Sixth",
        "Seventh",
        "Eighth",
        "Ninth",
        "Tenth",
        "Eleventh",
        "Twelfth"
    };

    char gifts[12][33] =
    {
        "Twelve drummers drumming",
        "Eleven pipers piping",
        "Ten lords a-leaping",
        "Nine ladies dancing",
        "Eight maids a-milking",
        "Seven swans a-swimming",
        "Six geese a-laying",
        "Five golden rings",
        "Four calling birds",
        "Three french hens", 
        "Two turtle doves", 
        "And a partridge in a pear tree."
    };
 
    for(i=0;i<12;i++)
    {
        printf("\n\nOn the %s day of Christmas\nMy true love gave to me:",days[i]);
 
        for(j=i;j>=0;j--)
        {
            (i==0)?printf("\nA partridge in a pear tree."):printf("\n%s%c",gifts[11-j],(j!=0)?',':' ');
        }
    }
 
    return 0;
}

C#

using System;

public class TwelveDaysOfChristmas {

    public static void Main() {

        string[] days = new string[12] {
            "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
            "tenth", "eleventh", "twelfth",
        };

        string[] gifts = new string[12] {
            "A partridge in a pear tree",
            "Two turtle doves",
            "Three french hens",
            "Four calling birds",
            "Five golden rings",
            "Six geese a-laying",
            "Seven swans a-swimming",
            "Eight maids a-milking",
            "Nine ladies dancing",
            "Ten lords a-leaping",
            "Eleven pipers piping",
            "Twelve drummers drumming"
        };

        for ( int i = 0; i < 12; i++ ) {

            Console.WriteLine("On the " + days[i] + " day of Christmas, my true love gave to me");

            int j = i + 1;
            while ( j-- > 0 )
                Console.WriteLine(gifts[j]);

            Console.WriteLine();

            if ( i == 0 )
                gifts[0] = "And a partridge in a pear tree";
        }

    }

}

C++

#include <iostream>
#include <array>
#include <string>
using namespace std;

int main()
{
    const array<string, 12> days
    {
        "first",
        "second",
        "third",
        "fourth",
        "fifth",
        "sixth",
        "seventh",
        "eighth",
        "ninth",
        "tenth",
        "eleventh",
        "twelfth"
    };
  
    const array<string, 12> gifts
    {
        "And a partridge in a pear tree",
        "Two turtle doves",
        "Three french hens",
        "Four calling birds",
        "FIVE GOLDEN RINGS",
        "Six geese a-laying",
        "Seven swans a-swimming",
        "Eight maids a-milking",
        "Nine ladies dancing",
        "Ten lords a-leaping",
        "Eleven pipers piping",
        "Twelve drummers drumming"
    };

    for(int i = 0; i < days.size(); ++i)
    {
        cout << "On the " << days[i] << " day of christmas, my true love gave to me\n";

        if(i == 0)
        {
            cout << "A partridge in a pear tree\n";
        }
        else
        {
            int j = i + 1;
            while(j-- > 0) cout << gifts[j] << '\n';
        }

        cout << '\n';
    }

    return 0;
}

Clojure

Translation of: Raku
(let
  [numbers '(first second third fourth fifth sixth
             seventh eighth ninth tenth eleventh twelfth)

   gifts   ["And a partridge in a pear tree",   "Two turtle doves",
            "Three French hens",                "Four calling birds",
            "Five gold rings",                  "Six geese a-laying",
            "Seven swans a-swimming",           "Eight maids a-milking",
            "Nine ladies dancing",              "Ten lords a-leaping",
            "Eleven pipers piping",             "Twelve drummers drumming"]

   day     (fn [n]
               (printf "On the %s day of Christmas, my true love sent to me\n"
                       (nth numbers n)))]

  (day 0)
  (println  (clojure.string/replace (first gifts) "And a" "A"))
  (dorun (for [d (range 1 12)] (do
    (println)
    (day d)
    (dorun (for [n (range d -1 -1)]
      (println (nth gifts n))))))))
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

CLU

christmas = cluster is carol
    rep = null
    
    own ordinals: array[string] := array[string]$[
        "first", "second", "third", "fourth", "fifth",
        "sixth", "seventh", "eighth", "ninth", "tenth",
        "eleventh", "twelfth"
    ]
    
    own gifts: array[string] := array[string]$[
        "A partridge in a pear tree.",
        "Two turtle doves, and",
        "Three french hens,",
        "Four calling birds,",
        "Five golden rings,",
        "Six geese a-laying,",
        "Seven swans a-swimming,",
        "Eight maids a-milking,",
        "Nine ladies dancing,",
        "Ten lords a-leaping,",
        "Eleven pipers piping,",
        "Twelve drummers drumming,"
    ]
    
    verse = proc (s: stream, n: int)
        stream$putl(s, "On the " || ordinals[n] || " day of Christmas,")
        stream$putl(s, "My true love gave to me:")
        for gift: int in int$from_to_by(n, 1, -1) do
            stream$putl(s, gifts[gift])
        end
        stream$putl(s, "")
    end verse
    
    carol = proc (s: stream)
        for n: int in int$from_to(1, 12) do
            verse(s, n)
        end
    end carol
end christmas

start_up = proc ()
    christmas$carol(stream$primary_output())
end start_up

COBOL

Works with: GNU Cobol version 2.0
       >>SOURCE FREE
PROGRAM-ID. twelve-days-of-christmas.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  gifts-area VALUE "partridge in a pear tree    "
    & "Two turtle doves              "
    & "Three french hens             "
    & "Four calling birds            "
    & "FIVE GOLDEN RINGS             "
    & "Six geese a-laying            "
    & "Seven swans a-swimming        "
    & "Eight maids a-milking         "
    & "Nine ladies dancing           "
    & "Ten lords a-leaping           "
    & "Eleven pipers piping          "
    & "Twelve drummers drumming      ".
    03  gifts                           PIC X(30) OCCURS 12 TIMES
                                        INDEXED BY gift-idx.

01  ordinals-area VALUE "first     second    third     fourth    fifth     "
    & "sixth     seventh   eighth    ninth     tenth     eleventh  twelfth   ".
    03  ordinals                        PIC X(10) OCCURS 12 TIMES.

01  day-num                             PIC 99 COMP.
                                        
PROCEDURE DIVISION.
    PERFORM VARYING day-num FROM 1 BY 1 UNTIL day-num > 12
        DISPLAY "On the " FUNCTION TRIM(ordinals (day-num)) " day of Christmas,"
            " my true love gave to me"

        IF day-num = 1
            DISPLAY "A " gifts (1)
        ELSE
            PERFORM VARYING gift-idx FROM day-num BY -1 UNTIL gift-idx = 1
                DISPLAY gifts (gift-idx)
            END-PERFORM
            DISPLAY "And a " gifts (1)
        END-IF
        
        DISPLAY SPACE
    END-PERFORM
    .
END PROGRAM twelve-days-of-christmas.

Common Lisp

let
  ((gifts '("A partridge in a pear tree." "Two turtle doves, and"
            "Three French hens,"          "Four calling birds,"
            "Five gold rings,"            "Six geese a-laying,"
            "Seven swans a-swimming,"     "Eight maids a-milking,"
            "Nine ladies dancing,"        "Ten lords a-leaping,"
            "Eleven pipers piping,"       "Twelve drummers drumming," )))

   (loop for day from 1 to 12 doing
     (format t "On the ~:r day of Christmas, my true love sent to me:~%" day)
     (loop for gift from (1- day) downto 0 doing
        (format t "~a~%" (nth gift gifts)))
     (format t "~%")))
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Cowgol

include "cowgol.coh";

var ordinals: [uint8][] := {
    "first","second","third","fourth","fifth",
    "sixth","seventh","eighth","ninth","tenth",
    "eleventh","twelfth"
};

var gifts: [uint8][] := {
    "Twelve drummers drumming",
    "Eleven pipers piping",
    "Ten lords a-leaping",
    "Nine ladies dancing",
    "Eight maids a-milking",
    "Seven swans a-swimming",
    "Six geese a-laying",
    "Five golden rings",
    "Four calling birds",
    "Three french hens",
    "Two turtle doves and",
    "A partridge in a pear tree."
};

var verse: @indexof ordinals := 0;
var gift: @indexof gifts;
while verse < 12 loop
    print("On the ");
    print(ordinals[verse]);
    print(" day of Christmas, my true love gave to me:\n");
    gift := 11 - verse;
    while gift < 12 loop
        print(gifts[gift]);
        print_nl();
        gift := gift + 1;
    end loop;
    print_nl();
    verse := verse + 1;
end loop;

Crystal

Translation of: Ruby
days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split " "
gifts = "A partridge in a pear tree
Two turtle doves and
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leaping
Eleven pipers piping
Twelve drummers drumming".split "\n"

days.each_with_index do |day, i|
    puts "On the #{day} day of Christmas\nMy true love gave to me:"
    gifts[0, i + 1].reverse.each &->puts(String)
    puts
end

D

Translation of: Python
immutable gifts =
"A partridge in a pear tree.
Two turtle doves
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leaping
Eleven pipers piping
Twelve drummers drumming";

immutable days = "first second third fourth fifth
                  sixth seventh eighth ninth tenth
                  eleventh twelfth";

void main() @safe {
    import std.stdio, std.string, std.range;

    foreach (immutable n, immutable day; days.split) {
        auto g = gifts.splitLines.take(n + 1).retro;
        writeln("On the ", day,
                " day of Christmas\nMy true love gave to me:\n",
                g[0 .. $ - 1].join('\n'),
                (n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
    }
}

dc

0 

d [first]                       r :n 
d [A partridge in a pear tree.] r :g 1 + 

d [second]                      r :n 
d [Two turtle doves and]        r :g 1 +

d [third]                       r :n 
d [Three French hens,]          r :g 1 +

d [fourth]                      r :n 
d [Four calling birds,]         r :g 1 +

d [fifth]                       r :n 
d [Five gold rings,]            r :g 1 +

d [sixth]                       r :n 
d [Six geese a-laying,]         r :g 1 +

d [seventh]                     r :n 
d [Seven swans a-swimming,]     r :g 1 +

d [eighth]                      r :n 
d [Eight maids a-milking,]      r :g 1 +

d [ninth]                       r :n 
d [Nine ladies dancing,]        r :g 1 +

d [tenth]                       r :n 
d [Ten lords a-leaping,]        r :g 1 +

d [eleventh]                    r :n 
d [Eleven pipers piping,]       r :g 1 +

d [twelfth]                     r :n 
  [Twelve drummers drumming,]   r :g 

[ 
  d 
  ;g n 
  10 P 
] sp

[ 
  d 
  0 r !<p 
  1 - 
  d 
  0 r !<r 
] sr
  
[ 
  [On the ] n 
  d ;n n 
  [ day of Christmas, my true love sent to me:] n 
  10 P 
  d 
  lr x s_
  10 P
  1 + 
  d 
  12 r <l
] sl 

0 ll x
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Delphi

Works with: Delphi version 6.0


const GiftList: array [0..11] of string =(
	'a partridge in a pear tree.',
	'Two turtle doves',
	'Three french hens',
	'Four calling birds',
	'Five golden rings',
	'Six geese a-laying',
	'Seven swans a-swimming',
	'Eight maids a-milking',
	'Nine ladies dancing',
	'Ten lords a-leaping',
	'Eleven pipers piping',
	'Twelve drummers drumming');

const Cardinals: array [0..11] of string =
	('first','second','third','forth',
	'fifth','sixth','seventh','eight',
	'ninth','tenth','eleventh','twelfth');

procedure DoOneDay(Memo: TMemo; Day: integer);
var S: string;
var I: integer;
begin
S:='On the '+Cardinals[Day]+' of Christmas ';
S:=S+'my true love gave to me'+CRLF;
for I:=Day downto 0 do
	begin
	if (Day>0) and (I=0) then S:=S+'and ';
	S:=S+GiftList[I]+CRLF;
	end;
Memo.Lines.Add(S);
end;

procedure TwelveDaysOfChristmas(Memo: TMemo);
var I: integer;
begin
for I:=0 to 12-1 do DoOneDay(Memo,I);
end;
Output:
On the first of Christmas my true love gave to me
a partridge in a pear tree.

On the second of Christmas my true love gave to me
Two turtle doves
and a partridge in a pear tree.

On the third of Christmas my true love gave to me
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the forth of Christmas my true love gave to me
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the fifth of Christmas my true love gave to me
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the sixth of Christmas my true love gave to me
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the seventh of Christmas my true love gave to me
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the eight of Christmas my true love gave to me
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the ninth of Christmas my true love gave to me
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the tenth of Christmas my true love gave to me
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the eleventh of Christmas my true love gave to me
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.

On the twelfth of Christmas my true love gave to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and a partridge in a pear tree.
Elapsed Time: 34.088 ms.


Dyalect

let days = [
    "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
    "tenth", "eleventh", "twelfth"
]
let gifts = [
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming"
]

for i in 0..11 {
    print("On the \(days[i]) day of Christmas, my true love gave to me.")
    for j in i^-1..0 {
        print(gifts[j])
    }
    print()
}

EasyLang

days$[] = [ "first" "second" "third" "forth" "fifth" "sixth" "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth" ]
gifts$[] &= "Twelve drummers drumming"
gifts$[] &= "Eleven pipers piping"
gifts$[] &= "Ten lords a-leaping"
gifts$[] &= "Nine ladies dancing"
gifts$[] &= "Eight maids a-milking"
gifts$[] &= "Seven swans a-swimming"
gifts$[] &= "Six geese a-laying"
gifts$[] &= "Five golden rings"
gifts$[] &= "Four calling birds"
gifts$[] &= "Three french hens"
gifts$[] &= "Two turtle doves and"
gifts$[] &= "A partridge in a pear tree."
for i = 1 to 12
   print "On the " & days$[i] & " day of Christmas,"
   print "My true love gave to me:"
   for j = 13 - i to 12
      print gifts$[j]
   .
   print ""
.

Eiffel

class
	APPLICATION

create
	make

feature

	make
		do
			twelve_days_of_christmas
		end

feature {NONE}

	twelve_days_of_christmas
			-- Christmas carol: Twelve days of christmas.
		local
			i, j: INTEGER
		do
			create gifts.make_empty
			create days.make_empty
			gifts := <<"A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming", "And a partridge in a pear tree.", "Two turtle doves">>
			days := <<"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "Twelfth">>
			from
				i := 1
			until
				i > days.count
			loop
				io.put_string ("On the " + days [i] + " day of Christmas.%N")
				io.put_string ("My true love gave to me:%N")
				from
					j := i
				until
					j <= 0
				loop
					if i = 12 and j = 2 then
						io.put_string (gifts [14] + "%N")
						io.put_string (gifts [13] + "%N")
						j := j - 1
					else
						io.put_string (gifts [j] + "%N")
					end
					j := j - 1
				end
				io.new_line
				i := i + 1
			end
		end

	gifts: ARRAY [STRING]

	days: ARRAY [STRING]

end

Elena

Translation of: C++

ELENA 6.x :

import extensions;
 
public program()
{
    var days := new string[]{
            "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
            "tenth", "eleventh", "twelfth"
            };
 
    var gifts := new string[]{
            "And a partridge in a pear tree",
            "Two turtle doves",
            "Three french hens",
            "Four calling birds",
            "Five golden rings",
            "Six geese a-laying",
            "Seven swans a-swimming",
            "Eight maids a-milking",
            "Nine ladies dancing",
            "Ten lords a-leaping",
            "Eleven pipers piping",
            "Twelve drummers drumming"
        };
 
    for(int i := 0; i < 12; i += 1)
    {
        console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");
 
        if (i == 0)
        {
            console.printLine("A partridge in a pear tree")
        }
        else
        {
            for(int j := i; j >= 0; j -= 1)
            {
                console.printLine(gifts[j])
            }
        };
 
        console.printLine()
    }
}

Elixir

gifts = """
A partridge in a pear tree
Two turtle doves and
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leaping
Eleven pipers piping
Twelve drummers drumming
""" |> String.split("\n", trim: true)

days = ~w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)

Enum.with_index(days) |> Enum.each(fn {day, i} ->
  IO.puts "On the #{day} day of Christmas"
  IO.puts "My true love gave to me:"
  Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
  IO.puts ""
end)
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree

...

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

Erlang

-module(twelve_days).
-export([gifts_for_day/1]).

names(N) -> lists:nth(N, 
              ["first",   "second", "third", "fourth", "fifth",    "sixth", 
               "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]).

gifts() -> [ "A partridge in a pear tree.", "Two turtle doves and",
             "Three French hens,",          "Four calling birds,",
             "Five gold rings,",            "Six geese a-laying,",
             "Seven swans a-swimming,",     "Eight maids a-milking,",
             "Nine ladies dancing,",        "Ten lords a-leaping,",
             "Eleven pipers piping,",       "Twelve drummers drumming," ].

gifts_for_day(N) -> 
  "On the " ++ names(N) ++ " day of Christmas, my true love sent to me:\n" ++
  string:join(lists:reverse(lists:sublist(gifts(), N)), "\n").

main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
                     lists:seq(1,12)).
Output:
On the first day of Christmas, my true love sent to me:

A partridge in a pear tree.

On the second day of Christmas, my true love sent to me: Two turtle doves and A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me: Twelve drummers drumming, Eleven pipers piping, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five gold rings, Four calling birds, Three French hens, Two turtle doves and

A partridge in a pear tree.

F#

let gifts = [
    "And a partridge in a pear tree";
    "Two turtle doves";
    "Three french hens";
    "Four calling birds";
    "FIVE GOLDEN RINGS";
    "Six geese a-laying";
    "Seven swans a-swimming";
    "Eight maids a-milking";
    "Nine ladies dancing";
    "Ten lords a-leaping";
    "Eleven pipers piping";
    "Twelve drummers drumming"
]

let days = [
    "first"; "second"; "third"; "fourth"; "fifth"; "sixth"; "seventh"; "eighth";
    "ninth"; "tenth"; "eleventh"; "twelfth"
]

let displayGifts day =
    printfn "On the %s day of Christmas, my true love gave to me" days.[day]
    if day = 0 then
        printfn "A partridge in a pear tree"
    else
        List.iter (fun i -> printfn "%s" gifts.[i]) [day..(-1)..0]
    printf "\n"
    
List.iter displayGifts [0..11]

Factor

USING: formatting io kernel math math.ranges qw sequences ;
IN: rosetta-code.twelve-days-of-christmas

CONSTANT: opener
    "On the %s day of Christmas, my true love sent to me:\n"

CONSTANT: ordinals qw{
    first second third fourth fifth sixth seventh eighth ninth
    tenth eleventh twelfth
}

CONSTANT: gifts {
    "A partridge in a pear tree."
    "Two turtle doves, and"
    "Three french hens,"
    "Four calling birds,"
    "Five golden rings,"
    "Six geese a-laying,"
    "Seven swans a-swimming,"
    "Eight maids a-milking,"
    "Nine ladies dancing,"
    "Ten lords a-leaping,"
    "Eleven pipers piping,"
    "Twelve drummers drumming,"
}

: descend ( n -- ) 0 [a,b] [ gifts nth print ] each nl ;

: verse ( n -- )
    1 - [ ordinals nth opener printf ] [ descend ] bi ;
    
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;

MAIN: twelve-days-of-christmas
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.

...

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

Fish

> 0 7 .                (0,0): Vector. Jumps to main, then used for sub returns
> 0 f 5 + .            (0,1): Print a NUL-terminated string
> 6 6 * 9 + f 8 + .    (0,2): Pop N, push Nth (e.g. 1 -> "first")
> 0 f 8 + .            (0,3): Pop N, push gift countdown starting from N.
> 0 f 1 + .            (0,4): Jump to line in range 16-30

main:
> 1                                                    \
/ a "On the " 0                                        <
\ "a" 4 0 p 0 1 .
> "b" 4 0 p : 0 2 .
> "c" 4 0 p 0 1 .
>                                                   \
/ " day of Christmas, my true love sent to me:" a 0 /
> "f" 4 0 p 0 1 .
> "1" 6 4 p "4" 4 0 p : 0 3 . 
> "2" 6 4 p 0 1 .
> 1 + : c ) ?\                                         /
             ;

> : ?\ ~ 0 0 .
\ o  /                                                    >   0 0 . 
                                                          ^ "first" 0 ~    \
>                                     \      > 1 - : ?\                    /
/ "A partridge in a pear tree." a 0 & <      /        /   ^ "second" 0 ~   \
\ & 1 - : ?\ ~ 0 0 .                         \ 1 - : ?\                    /
           \                  \              /        /   ^ "third" 0 ~    \
/ "Two turtle doves and" a &  /              \ 1 - : ?\                    /
\ & 1 - : ?\ ~ 0 0 .                         /        /   ^ "fourth" 0 ~   \
           \               \                 \ 1 - : ?\                    /
/ "Three French hens," a & /                 /        /   ^ "fifth" 0 ~    \
\ & 1 - : ?\ ~ 0 0 .                         \ 1 - : ?\                    /
           \                \                /        /   ^ "sixth" 0 ~    \
/ "Four calling birds," a & /                \ 1 - : ?\                    /
\ & 1 - : ?\ ~ 0 0 .                         /        /   ^ "seventh" 0 ~  \
           \             \                   \ 1 - : ?\                    /
/ "Five gold rings," a & /                   /        /   ^ "eighth" 0 ~   \
\ & 1 - : ?\ ~ 0 0 .                         \ 1 - : ?\                    /
           \                \                /        /   ^ "ninth" 0 ~    \
/ "Six geese a-laying," a & /                \ 1 - : ?\                    /
\ & 1 - : ?\ ~ 0 0 .                         /        /   ^ "tenth" 0 ~    \
           \                    \            \ 1 - : ?\                    /
/ "Seven swans a-swimming," a & /            /        /   ^ "eleventh" 0 ~ \
\ & 1 - : ?\ ~ 0 0 .                         \ 1 - : ?\                    /
           \                   \                      \                    \
/ "Eight maids a-milking," a & /                          ^ "twelfth" 0 ~  /
\ & 1 - : ?\ ~ 0 0 .
           \                 \
/ "Nine ladies dancing," a & /
\ & 1 - : ?\ ~ 0 0 .
           \                 \
/ "Ten lords a-leaping," a & /
\ & 1 - : ?\ ~ 0 0 .
           \                  \
/ "Eleven pipers piping," a & /
\ & 1 - : ?\ ~ 0 0 .
           \                      \
/ "Twelve drummers drumming," a & /
\ & ~ 0 0 .
Output:
On the first day of Christmas, my true love gave to me:
A partridge in a pear tree.

On the second day of Christmas, my true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]


On the twelfth day of Christmas, my true love gave to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Forth

Works with: GNU Forth
create ordinals s" first" 2, s" second" 2, s" third"    2, s" fourth" 2,
                s" fifth" 2, s" sixth"  2, s" seventh"  2, s" eighth" 2,
                s" ninth" 2, s" tenth"  2, s" eleventh" 2, s" twelfth" 2,
: ordinal ordinals swap 2 * cells + 2@ ;
 
create gifts s" A partridge in a pear tree." 2,
             s" Two turtle doves and" 2,
             s" Three French hens," 2,
             s" Four calling birds," 2,
             s" Five gold rings," 2,
             s" Six geese a-laying," 2,
             s" Seven swans a-swimming," 2,
             s" Eight maids a-milking," 2,
             s" Nine ladies dancing," 2,
             s" Ten lords a-leaping," 2,
             s" Eleven pipers piping," 2,
             s" Twelve drummers drumming," 2,
: gift gifts swap 2 * cells + 2@ ;
 
: day 
  s" On the " type 
  dup ordinal type
  s"  day of Christmas, my true love sent to me:" type
  cr
  -1 swap -do
    i gift type cr
  1 -loop
  cr
  ;
 
: main 
  12 0 do i day loop
;
 
main
bye
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Fortran

Works with: FORTRAN version 77
      program twelve_days

      character days(12)*8
      data days/'first', 'second', 'third',    'fourth',
     c          'fifth', 'sixth',  'seventh',  'eighth',
     c          'ninth', 'tenth',  'eleventh', 'twelfth'/

      character gifts(12)*27
      data gifts/'A partridge in a pear tree.',
     c           'Two turtle doves and',
     c           'Three French hens,',
     c           'Four calling birds,',
     c           'Five gold rings,',
     c           'Six geese a-laying,',
     c           'Seven swans a-swimming,',
     c           'Eight maids a-milking,',
     c           'Nine ladies dancing,',
     c           'Ten lords a-leaping,',
     c           'Eleven pipers piping,',
     c           'Twelve drummers drumming,'/

      integer day, gift

      do 10 day=1,12
        write (*,'(a)') 'On the ', trim(days(day)),
     c              ' day of Christmas, my true love sent to me:'
        do 20 gift=day,1,-1
          write (*,'(a)') trim(gifts(gift))
  20    continue
        write(*,*)
  10  continue
      end
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

 [...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

FreeBASIC

' version 10-01-2017
' compile with: fbc -s console

Dim As ULong d, r

Dim As String days(1 To ...) = { "first", "second", "third", "fourth", _
                                "fifth", "sixth", "seventh", "eighth", _
                              "ninth", "tenth", "eleventh", "twelfth" }

Dim As String gifts(1 To ...) = { "", " Two turtle doves", _
              " Three french hens", " Four calling birds", _
              " Five golden rings", " Six geese a-laying", _
      " Seven swans a-swimming", " Eight maids a-milking", _
           " Nine ladies dancing", " Ten lords a-leaping", _
     " Eleven pipers piping", " Twelve drummers drumming" }

For d = 1 To 12
    Print " On the " + days(d) + " day of Christmas"
    Print " My true love gave to me:"
    For r = d To 3 Step -1
        Print gifts(r)
    Next
    ' print " Two turtle doves" for the twelfth day and add "and" for the other days
    If d > 1 Then
        Print gifts(2); iif(d = 12, "", " and")
    End If
    ' print "A partridge...", on the twelfth day print "And a partrige..."
    Print " A" & IIf(d = 12, "nd a", "" ) & " partridge in a pear tree"
    Print
Next

' empty keyboard buffer
While Inkey <> "" : Wend
Print : 'Print "hit any key to end program"
Sleep
End
Output:
 On the first day of Christmas
 My true love gave to me:
 A partridge in a pear tree

 On the second day of Christmas
 My true love gave to me:
 Two turtle doves and
 A partridge in a pear tree

 '''

 On the twelfth day of Christmas
 My true love gave to me:
 Twelve drummers drumming
 Eleven pipers piping
 Ten lords a-leaping
 Nine ladies dancing
 Eight maids a-milking
 Seven swans a-swimming
 Six geese a-laying
 Five golden rings
 Four calling birds
 Three french hens
 Two turtle doves
 And a partridge in a pear tree

Go

Go Playground

package main

import (
	"fmt"
)

func main() {
	days := []string{"first", "second", "third", "fourth", "fifth", "sixth",
		"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}

	gifts := []string{"A Partridge in a Pear Tree", "Two Turtle Doves and", "Three French Hens",
		"Four Calling Birds", "Five Gold Rings", "Six Geese a-Laying",
		"Seven Swans a-Swimming", "Eight Maids a-Milking", "Nine Ladies Dancing",
		"Ten Lords a-Leaping", "Eleven Pipers Piping", "Twelve Drummers Drumming"}

	for i := 0; i < 12; i++ {
		fmt.Printf("On the %s day of Christmas,\n", days[i])
		fmt.Println("My true love sent to me:")

		for j := i; j >= 0; j-- {
			fmt.Println(gifts[j])
		}
		fmt.Println()
	}
}

Groovy

def presents = ['A partridge in a pear tree.', 'Two turtle doves', 'Three french hens', 'Four calling birds',
        'Five golden rings', 'Six geese a-laying', 'Seven swans a-swimming', 'Eight maids a-milking',
        'Nine ladies dancing', 'Ten lords a-leaping', 'Eleven pipers piping', 'Twelve drummers drumming']
['first', 'second', 'third', 'forth', 'fifth', 'sixth', 'seventh', 'eight', 'ninth', 'tenth', 'eleventh', 'Twelfth'].eachWithIndex{ day, dayIndex ->
    println "On the $day day of Christmas"
    println 'My true love gave to me:'
    (dayIndex..0).each { p ->
        print presents[p]
        println p == 1 ? ' and' : ''
    }
    println()
}

Haskell

Translation of: F#
gifts :: [String]
gifts =
  [ "And a partridge in a pear tree!",
    "Two turtle doves,",
    "Three french hens,",
    "Four calling birds,",
    "FIVE GOLDEN RINGS,",
    "Six geese a-laying,",
    "Seven swans a-swimming,",
    "Eight maids a-milking,",
    "Nine ladies dancing,",
    "Ten lords a-leaping,",
    "Eleven pipers piping,",
    "Twelve drummers drumming,"
  ]

days :: [String]
days =
  [ "first",
    "second",
    "third",
    "fourth",
    "fifth",
    "sixth",
    "seventh",
    "eighth",
    "ninth",
    "tenth",
    "eleventh",
    "twelfth"
  ]

verseOfTheDay :: Int -> IO ()
verseOfTheDay day = do
  putStrLn $
    "On the " <> days !! day
      <> " day of Christmas my true love gave to me... "
  mapM_ putStrLn [dayGift day d | d <- [day, day -1 .. 0]]
  putStrLn ""
  where
    dayGift 0 _ = "A partridge in a pear tree!"
    dayGift _ gift = gifts !! gift

main :: IO ()
main = mapM_ verseOfTheDay [0 .. 11]
Output:
On the first day of Christmas my true love gave to me... 
A partridge in a pear tree!

On the second day of Christmas my true love gave to me... 
Two turtle doves,
And a partridge in a pear tree!

On the third day of Christmas my true love gave to me... 
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the fourth day of Christmas my true love gave to me... 
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the fifth day of Christmas my true love gave to me... 
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the sixth day of Christmas my true love gave to me... 
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the seventh day of Christmas my true love gave to me... 
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the eighth day of Christmas my true love gave to me... 
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the ninth day of Christmas my true love gave to me... 
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the tenth day of Christmas my true love gave to me... 
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the eleventh day of Christmas my true love gave to me... 
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

On the twelfth day of Christmas my true love gave to me... 
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree!

Icon and Unicon

Works in both languages.

procedure main()
    days := ["first","second","third","fourth","fifth","sixth","seventh",
             "eighth","ninth","tenth","eleventh","twelveth"]
    gifts := ["A partridge in a pear tree.", "Two turtle doves and",
              "Three french hens,", "Four calling birds,",
              "Five golden rings,", "Six geese a-laying,",
              "Seven swans a-swimming,", "Eight maids a-milking,",
              "Nine ladies dancing,", "Ten lords a-leaping,",
              "Eleven pipers piping,", "Twelve drummers drumming,"]

    every write("\nOn the ",days[day := 1 to 12]," day of Christmas my true love gave to me:") do
        every write(" ",gifts[day to 1 by -1])
end

J

require 'strings'  NB. not necessary for versions > j6

days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'

gifts=: <;.2 ] 0 : 0
And a partridge in a pear tree.
Two turtle doves,
Three french hens,
Four calling birds,
Five golden rings,
Six geese a-laying,
Seven swans a-swimming,
Eight maids a-milking,
Nine ladies dancing,
Ten lords a-leaping,
Eleven pipers piping,
Twelve drummers drumming,
)

firstline=: 'On the ' , ,&(' day of Christmas, my true love gave to me',LF)

chgFirstVerse=: rplc&('nd a';'')&.>@{. , }.

makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_

singCarol=: LF joinstring makeVerses

Janet

(def days ["first" "second" "third"
           "fourth" "fifth" "sixth"
           "seventh" "eighth" "ninth"
           "tenth" "eleventh" "twelfth"])
(def gifts ["A partridge in a pear tree."
            "Two turtle doves and"
            "Three french hens"
            "Four calling birds"
            "Five golden rings"
            "Six geese a-laying"
            "Seven swans a-swimming"
            "Eight maids a-milking"
            "Nine ladies dancing"
            "Ten lords a-leaping"
            "Eleven pipers piping"
            "Twelve drummers drumming"])
(var v "")
(eachp [i d] days
  (print "On the " d " day of Christmas")
  (print "My true love gave to me")
  (set v (string (in gifts i) "\n" v))
  (print v))

Java

public class TwelveDaysOfChristmas {

    final static String[] gifts = {
        "A partridge in a pear tree.", "Two turtle doves and",
        "Three french hens", "Four calling birds",
        "Five golden rings", "Six geese a-laying",
        "Seven swans a-swimming", "Eight maids a-milking",
        "Nine ladies dancing", "Ten lords a-leaping",
        "Eleven pipers piping", "Twelve drummers drumming",
        "And a partridge in a pear tree.", "Two turtle doves"
    };

    final static String[] days = {
        "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
        "eighth", "ninth", "tenth", "eleventh", "Twelfth"
    };

    public static void main(String[] args) {
        for (int i = 0; i < days.length; i++) {
            System.out.printf("%nOn the %s day of Christmas%n", days[i]);
            System.out.println("My true love gave to me:");
            for (int j = i; j >= 0; j--)
                System.out.println(gifts[i == 11 && j < 2 ? j + 12 : j]);
        }
    }
}

JavaScript

var days = [
    'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
    'tenth', 'eleventh', 'twelfth',
];

var gifts = [
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming"
];

var lines, verses = [], song;

for ( var i = 0; i < 12; i++ ) {

    lines = [];
    lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
    
    var j = i + 1;
    var k = 0;
    while ( j-- > 0 )
        lines[++k] = gifts[j];

    
    verses[i] = lines.join('\n');
    
    if ( i == 0 )
        gifts[0] = "And a partridge in a pear tree";
    
}

song = verses.join('\n\n');
document.write(song);


Alternatively, in a functional style of JavaScript, we can define the ancient song "strPrepn the lstOrdinal[i] strUnit of strHoliday" as an expression, and return that expression in a human-legible and machine-parseable JSON string translation, for further analysis and processing :-)

JSON.stringify(
  (function (
    strPrepn,
    strHoliday,
    strUnit,
    strRole,
    strProcess,
    strRecipient
  ) {
    var lstOrdinal =
      'first second third fourth fifth sixth\
           seventh eighth ninth tenth eleventh twelfth'
      .split(/\s+/),
      lngUnits = lstOrdinal.length,

      lstGoods =
      'A partridge in a pear tree.\
           Two turtle doves\
           Three french hens\
           Four calling birds\
           Five golden rings\
           Six geese a-laying\
           Seven swans a-swimming\
           Eight maids a-milking\
           Nine ladies dancing\
           Ten lords a-leaping\
           Eleven pipers piping\
           Twelve drummers drumming'
      .split(/\s{2,}/),

      lstReversed = (function () {
        var lst = lstGoods.slice(0);
        return (lst.reverse(), lst);
      })(),

      strProvenance = [strRole, strProcess, strRecipient + ':'].join(' '),

      strPenultimate = lstReversed[lngUnits - 2] + ' and',
      strFinal = lstGoods[0];

    return lstOrdinal.reduce(
      function (sofar, day, i) {
        return sofar.concat(
          [
            [
              [ // abstraction of line 1
                strPrepn,
                'the',
                lstOrdinal[i],
                strUnit,
                'of',
                strHoliday
              ].join(' '),
              strProvenance
            ].concat( // reversed descent through memory
              (i > 1 ? [lstGoods[i]] : []).concat(
                lstReversed.slice(
                  lngUnits - i,
                  lngUnits - 2
                )
              ).concat( // penultimate line ends with 'and'
                [
                  strPenultimate,
                  strFinal
                ].slice(i ? 0 : 1)
              )
            )
          ]
        );
      }, []
    );
  })(
    'On', 'Christmas', 'day', 'my true love', 'gave to', 'me'
  ), null, 2
);

Note that the Google Closure compiler's translation of this would be half the size, but rather less legible. (It does make interesting suggestions though – the semi-colon segmentation of the verses below is a trick that might be worth remembering).

JSON.stringify(function (h, k, l, f, m, n) {
  var c =
    "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
    .split(" "),
    d = c.length,
    e =
    "A partridge in a pear tree.;Two turtle doves;Three french hens;Four calling birds;Five golden rings;Six geese a-laying;Seven swans a-swimming;Eight maids a-milking;Nine ladies dancing;Ten lords a-leaping;Eleven pipers piping;Twelve drummers drumming"
    .split(";"),
    g = function () {
      var b = e.slice(0);
      return b.reverse(), b;
    }(),
    p = [f, m, n + ":"].join(" "),
    q = g[d - 2] + " and",
    r = e[0];
    
  return c.reduce(function (b, f, a) {
    return b.concat([[[h, "the", c[a], l, "of", k].join(" "), p].concat((1 <
      a ? [e[a]] : []).concat(g.slice(d - a, d - 2)).concat([q, r].slice(a ?
      0 : 1)))]);
  }, []);
}("On", "Christmas", "day", "my true love", "gave to", "me"), null, 2);

Formatted JSON output (the expanded and Closure-compiled versions above both yield the same output).

[
  [
    "On the first day of Christmas",
    "my true love gave to me:",
    "A partridge in a pear tree."
  ],
  [
    "On the second day of Christmas",
    "my true love gave to me:",
    "Two turtle doves and",
    "A partridge in a pear tree."
  ],
  [
    "On the third day of Christmas",
    "my true love gave to me:",
    "Three french hens",
    "Two turtle doves and",
    "A partridge in a pear tree."
  ],
  [
    "On the fourth day of Christmas",
    "my true love gave to me:",
    "Four calling birds",
    "Three french hens",
    "Two turtle doves and",
    "A partridge in a pear tree."
  ],
  [
    "On the fifth day of Christmas",
    "my true love gave to me:",
    "Five golden rings",
    "Four calling birds",
    "Three french hens",
    "Two turtle doves and",
    "A partridge in a pear tree."
  ]

//... etc.

]

jq

[ "one", "two", "three", "four", "five", "six",
    "seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
| [ "first", "second", "third", "fourth", "fifth", "sixth",
    "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"] as $ordinals
| [ "a partridge in a pear tree.", "turtle doves", "French hens",
    "calling birds", "gold rings", "geese a-laying", "swans a-swimming",
    "maids a-milking", "ladies dancing", "lords a-leaping", "pipers piping",
    "drummers drumming" ] as $gifts
| range(12) | . as $i | $ordinals[$i] as $nth
| "On the " + $nth + " day of Christmas, my true love sent to me:\n" +
  ([[range($i+1)]|reverse[]|. as $j|$cardinals[$j] as $count|
     if $j > 0 then $count else if $i > 0 then "and" else "" end end + 
      " " + $gifts[$j] + if $j > 0 then "," else "\n" end]
  | join("\n"))

Run with

jq -rnf programfile.jq

to yield this result:

Output:
On the first day of Christmas, my true love sent to me:
 a partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
two turtle doves,
and a partridge in a pear tree.

On the third day of Christmas, my true love sent to me:
three French hens,
two turtle doves,
and a partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
twelve drummers drumming,
eleven pipers piping,
ten lords a-leaping,
nine ladies dancing,
eight maids a-milking,
seven swans a-swimming,
six geese a-laying,
five gold rings,
four calling birds,
three French hens,
two turtle doves,
and a partridge in a pear tree.

Jsish

Based on Javascript entry, almost identical, added unitTest.

#!/usr/bin/env jsish
"use strict";

/* Twelve Days Of Christmas, in Jsish */
var days = [
    'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
    'tenth', 'eleventh', 'twelfth'
];
 
var gifts = [
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming"
];
 
var lines, verses = [], song;
 
for ( var i = 0; i < 12; i++ ) {
    lines = [];
    lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
 
    var j = i + 1;
    var k = 0;
    while ( j-- > 0 )
        lines[++k] = gifts[j];
 
    verses[i] = lines.join('\n');
 
    if ( i == 0 )
        gifts[0] = "And a partridge in a pear tree";
}
 
song = verses.join('\n\n');
;song;

/*
=!EXPECTSTART!=
song ==> On the first day of Christmas, my true love gave to me
A partridge in a pear tree

On the second day of Christmas, my true love gave to me
Two turtle doves
And a partridge in a pear tree

On the third day of Christmas, my true love gave to me
Three french hens
Two turtle doves
And a partridge in a pear tree

On the fourth day of Christmas, my true love gave to me
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the fifth day of Christmas, my true love gave to me
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the sixth day of Christmas, my true love gave to me
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the seventh day of Christmas, my true love gave to me
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the eighth day of Christmas, my true love gave to me
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the ninth day of Christmas, my true love gave to me
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the tenth day of Christmas, my true love gave to me
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the eleventh day of Christmas, my true love gave to me
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree

On the twelfth day of Christmas, my true love gave to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree
=!EXPECTEND!=
*/
Output:

The verses are in the unitTest. --U mode to show the echo mode output skipped here.

prompt$ jsish -u twelveDaysOfChristmas.jsi
[PASS] twelveDaysOfChristmas.jsi

Julia

# v0.6.0

function printlyrics()
    const gifts = split("""
    A partridge in a pear tree.
    Two turtle doves
    Three french hens
    Four calling birds
    Five golden rings
    Six geese a-laying
    Seven swans a-swimming
    Eight maids a-milking
    Nine ladies dancing
    Ten lords a-leaping
    Eleven pipers piping
    Twelve drummers drumming
    """, '\n')
    const days = split("""
    first second third fourth fifth
    sixth seventh eighth ninth tenth
    eleventh twelfth""")
    for (n, day) in enumerate(days)
        g = gifts[n:-1:1]
        print("\nOn the $day day of Christmas\nMy true love gave to me:\n")
        if n == 1
            print(join(g[1:end], '\n'), '\n')
        else
            print(join(g[1:end-1], '\n'), " and\n", g[end], '\n')
        end
    end
end

printlyrics()
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

Kotlin

Translation of: C#
enum class Day {
    first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth;
    val header = "On the " + this + " day of Christmas, my true love sent to me\n\t"
}

fun main(x: Array<String>) {
    val gifts = listOf("A partridge in a pear tree",
                       "Two turtle doves and",
                       "Three french hens",
                       "Four calling birds",
                       "Five golden rings",
                       "Six geese a-laying",
                       "Seven swans a-swimming",
                       "Eight maids a-milking",
                       "Nine ladies dancing",
                       "Ten lords a-leaping",
                       "Eleven pipers piping",
                       "Twelve drummers drumming")

    Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
}

Lambdatalk

{def days
   first second third fourth fifth sixth
   seventh eight ninth tenth eleventh twelfth}
-> days
 
{def texts
   {quote A partridge in a pear tree.}
   {quote Two turtle doves and}
   {quote Three french hens}
   {quote Four calling birds}
   {quote Five golden rings}
   {quote Six geese a-laying}
   {quote Seven swans a-swimming}
   {quote Eight maids a-milking}
   {quote Nine ladies dancing}
   {quote Ten lords a-leaping}
   {quote Eleven pipers piping}
   {quote Twelve drummers drumming}} 
-> texts

{S.map {lambda {:i} {hr}On the {S.get :i {days}} day of Christmas
                    {br}My true love gave to me               
                    {S.map {lambda {:i} {br}{S.get :i {texts}}} 
                           {S.serie :i 0 -1}} 
       } {S.serie 0 {- {S.length {days}} 1}}}   
-> 
On the first day of Christmas 
My true love gave to me 
A partridge in a pear tree. 

On the second day of Christmas 
My true love gave to me 
Two turtle doves and 
A partridge in a pear tree. 

...

On the twelfth day of Christmas 
My true love gave to me 
Twelve drummers drumming 
Eleven pipers piping 
Ten lords a-leaping 
Nine ladies dancing 
Eight maids a-milking 
Seven swans a-swimming 
Six geese a-laying 
Five golden rings 
Four calling birds 
Three french hens 
Two turtle doves and 
A partridge in a pear tree.

make "numbers [first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth]
make "gifts   [[And a partridge in a pear tree] [Two turtle doves]     [Three French hens]
               [Four calling birds]             [Five gold rings]      [Six geese a-laying]
               [Seven swans a-swimming]         [Eight maids a-miling] [Nine ladies dancing]
               [Ten lords a-leaping]            [Eleven pipers piping] [Twelve drummers drumming]]

to nth :n
  print (sentence [On the] (item :n :numbers) [day of Christmas, my true love sent to me])
end

nth 1
print [A partridge in a pear tree]

for [d 2 12] [
  print []
  nth :d
  for [g :d 1] [
    print item :g gifts
  ]
]
bye
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

LOLCODE

Works with: LCI 0.10
HAI 1.2
CAN HAS STDIO?

I HAS A Dayz ITZ A BUKKIT
Dayz HAS A SRS  1 ITZ "first"
Dayz HAS A SRS  2 ITZ "second"
Dayz HAS A SRS  3 ITZ "third"
Dayz HAS A SRS  4 ITZ "fourth"
Dayz HAS A SRS  5 ITZ "fifth"
Dayz HAS A SRS  6 ITZ "sixth"
Dayz HAS A SRS  7 ITZ "seventh"
Dayz HAS A SRS  8 ITZ "eighth"
Dayz HAS A SRS  9 ITZ "ninth"
Dayz HAS A SRS 10 ITZ "tenth"
Dayz HAS A SRS 11 ITZ "eleventh"
Dayz HAS A SRS 12 ITZ "twelfth"

I HAS A Prezents ITZ A BUKKIT
Prezents HAS A SRS  1 ITZ "A partridge in a pear tree"
Prezents HAS A SRS  2 ITZ "Two turtle doves"
Prezents HAS A SRS  3 ITZ "Three French hens"
Prezents HAS A SRS  4 ITZ "Four calling birds"
Prezents HAS A SRS  5 ITZ "Five gold rings"
Prezents HAS A SRS  6 ITZ "Six geese a-laying"
Prezents HAS A SRS  7 ITZ "Seven swans a-swimming"
Prezents HAS A SRS  8 ITZ "Eight maids a-milking"
Prezents HAS A SRS  9 ITZ "Nine ladies dancing"
Prezents HAS A SRS 10 ITZ "Ten lords a-leaping"
Prezents HAS A SRS 11 ITZ "Eleven pipers piping"
Prezents HAS A SRS 12 ITZ "Twelve drummers drumming"

IM IN YR Outer UPPIN YR i WILE DIFFRINT i AN 12
  I HAS A Day ITZ SUM OF i AN 1
  VISIBLE "On the " !
  VISIBLE Dayz'Z SRS Day !
  VISIBLE " day of Christmas, my true love sent to me"
  IM IN YR Inner UPPIN YR j WILE DIFFRINT j AN  Day
    I HAS A Count ITZ DIFFERENCE OF Day AN j
    VISIBLE Prezents'Z SRS Count
  IM OUTTA YR Inner
  BOTH SAEM i AN 0 
  O RLY? 
    YA RLY
      Prezents'Z SRS 1 R "And a partridge in a pear tree"
  OIC
  DIFFRINT i AN 11
    O RLY?
      YA RLY
        VISIBLE ""
  OIC
IM OUTTA YR Outer
  
KTHXBYE
Output:
On the first day of Christmas, my true love sent to me
A partridge in a pear tree

On the second day of Christmas, my true love sent to me
Two turtle doves
And a partridge in a pear tree

[...]

On the twelfth day of Christmas, my true love sent to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five gold rings
Four calling birds
Three French hens
Two turtle doves
And a partridge in a pear tree

Lua

local days = {
    'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
    'tenth', 'eleventh', 'twelfth',
}

local gifts = {
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming",
}

local verses = {}

for i = 1, 12 do
    local lines = {}
    lines[1] = "On the " .. days[i] .. " day of Christmas, my true love gave to me"
    
    local j = i
    local k = 2
    repeat
        lines[k] = gifts[j]
        k = k + 1
        j = j - 1
    until j == 0
    
    verses[i] = table.concat(lines, '\n')
end

print(table.concat(verses, '\n\n'))

MACRO-11

        .TITLE  CAROL
        .MCALL  .TTYOUT,.EXIT
CAROL:: CLR     R5
1$:     MOV     #ONTHE,R1
        JSR     PC,PRINT
        MOV     ORDTAB(R5),R1
        JSR     PC,PRINT
        MOV     #DAYOF,R1
        JSR     PC,PRINT
        MOV     VRSTAB(R5),R1
        JSR     PC,PRINT
        ADD     #2,R5
        CMP     R5,#^D24
        BLT     1$
        .EXIT

PRINT:  MOVB    (R1)+,R0
        .TTYOUT
        BNE     PRINT
        RTS     PC

ONTHE:  .ASCIZ  /On the /
ORDTAB: .WORD   1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
1$:     .ASCIZ  /first/
2$:     .ASCIZ  /second/
3$:     .ASCIZ  /third/
4$:     .ASCIZ  /fourth/
5$:     .ASCIZ  /fifth/
6$:     .ASCIZ  /sixth/
7$:     .ASCIZ  /seventh/
8$:     .ASCIZ  /eighth/
9$:     .ASCIZ  /ninth/
10$:    .ASCIZ  /tenth/
11$:    .ASCIZ  /eleventh/
12$:    .ASCIZ  /twelfth/
DAYOF:  .ASCIZ  / day of Christmas, my true love gave to me:/<15><12>
VRSTAB: .WORD   1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
12$:    .ASCII  /Twelve drummers drumming/<15><12>
11$:    .ASCII  /Eleven pipers piping/<15><12>
10$:    .ASCII  /Ten lords a-leaping/<15><12>
9$:     .ASCII  /Nine ladies dancing/<15><12>
8$:     .ASCII  /Eight maids a-milking/<15><12>
7$:     .ASCII  /Seven swans a-swimming/<15><12>
6$:     .ASCII  /Six geese a-laying/<15><12>
5$:     .ASCII  /Five golden rings/<15><12>
4$:     .ASCII  /Four calling birds/<15><12>
3$:     .ASCII  /Three French hens/<15><12>
2$:     .ASCII  /Two turtle doves, and/<15><12>
1$:     .ASCIZ  /A partridge in a pear tree./<15><12><15><12>
        .END    CAROL


MAD

            NORMAL MODE IS INTEGER
            
            THROUGH VERSE, FOR I=1, 1, I.G.12
            PRINT FORMAT XMS,ORD(I)
            PRINT FORMAT TLV
            TRANSFER TO GIFT(13-I)
GIFT(1)     PRINT FORMAT G12
GIFT(2)     PRINT FORMAT G11
GIFT(3)     PRINT FORMAT G10
GIFT(4)     PRINT FORMAT G9
GIFT(5)     PRINT FORMAT G8
GIFT(6)     PRINT FORMAT G7
GIFT(7)     PRINT FORMAT G6
GIFT(8)     PRINT FORMAT G5
GIFT(9)     PRINT FORMAT G4
GIFT(10)    PRINT FORMAT G3
GIFT(11)    PRINT FORMAT G2
GIFT(12)    PRINT FORMAT G1
VERSE       PRINT FORMAT MT
            
            VECTOR VALUES XMS = 
          0        $7HON THE ,C,S1,16HDAY OF CHRISTMAS*$
            VECTOR VALUES ORD = $*$, $FIRST$, $SECOND$, $THIRD$
          0 ,      $FOURTH$, $FIFTH$, $SIXTH$, $SEVENTH$, $EIGHTH$
          1 ,      $NINTH$, $TENTH$, $ELEVENTH$, $TWELFTH$
            VECTOR VALUES TLV = $23HMY TRUE LOVE GAVE TO ME*$
            VECTOR VALUES G12 = $24HTWELVE DRUMMERS DRUMMING*$
            VECTOR VALUES G11 = $20HELEVEN PIPERS PIPING*$
            VECTOR VALUES G10 = $19HTEN LORDS A-LEAPING*$
            VECTOR VALUES G9  = $19HNINE LADIES DANCING*$
            VECTOR VALUES G8  = $21HEIGHT MAIDS A-MILKING*$
            VECTOR VALUES G7  = $22HSEVEN SWANS A-SWIMMING*$
            VECTOR VALUES G6  = $18HSIX GEESE A-LAYING*$
            VECTOR VALUES G5  = $17HFIVE GOLDEN RINGS*$
            VECTOR VALUES G4  = $18HFOUR CALLING BIRDS*$
            VECTOR VALUES G3  = $17HTHREE FRENCH HENS*$
            VECTOR VALUES G2  = $20HTWO TURTLE DOVES AND*$
            VECTOR VALUES G1  = $26HA PARTRIDGE IN A PEAR TREE*$
            VECTOR VALUES MT  = $*$
            END OF PROGRAM

Maple

gifts := ["Twelve drummers drumming",
		"Eleven pipers piping", "Ten lords a-leaping",
		"Nine ladies dancing", "Eight maids a-milking",
		"Seven swans a-swimming", "Six geese a-laying",
		"Five golden rings", "Four calling birds",
		"Three french hens", "Two turtle doves and", "A partridge in a pear tree"]:
days := ["first", "second", "third", "fourth", "fifth", "sixth",
		"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]:
for i to 12 do
	printf("On the %s day of Christmas\nMy true love gave to me:\n", days[i]);
	for j from 13-i to 12 do
		printf("%s\n", gifts[j]);
	end do;
	printf("\n");
end do;
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree

On the third day of Christmas
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree

...

On the eleventh day of Christmas
My true love gave to me:
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

Mathematica/Wolfram Language

daysarray = {"first", "second", "third", "fourth", "fifth", "sixth", 
   "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
giftsarray = {"And a partridge in a pear tree.", "Two turtle doves", 
   "Three french hens", "Four calling birds", "FIVE GOLDEN RINGS", 
   "Six geese a-laying", "Seven swans a-swimming,", 
   "Eight maids a-milking", "Nine ladies dancing", 
   "Ten lords a-leaping", "Eleven pipers piping", 
   "Twelve drummers drumming"};
Do[Print[StringForm[
   "On the `1` day of Christmas, my true love gave to me: `2`", 
   daysarray[[i]], 
   If[i == 1, "A partridge in a pear tree.", 
    Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]
Output:
On the first day of Christmas, my true love gave to me: 
A partridge in a pear tree.

On the second day of Christmas, my true love gave to me: 
Two turtle doves,
And a partridge in a pear tree.

On the third day of Christmas, my true love gave to me: 
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the fourth day of Christmas, my true love gave to me: 
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the fifth day of Christmas, my true love gave to me: 
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the sixth day of Christmas, my true love gave to me: 
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the seventh day of Christmas, my true love gave to me: 
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the eighth day of Christmas, my true love gave to me: 
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the ninth day of Christmas, my true love gave to me: 
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the tenth day of Christmas, my true love gave to me: 
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the eleventh day of Christmas, my true love gave to me: 
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the twelfth day of Christmas, my true love gave to me: 
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GOLDEN RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

MiniScript

days = ["first","second","third", "fourth","fifth","sixth",
        "seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
        "Three French hens,","Four calling birds,",
        "Five gold rings,","Six geese a-laying,",
        "Seven swans a-swimming,","Eight maids a-milking,",
        "Nine ladies dancing,","Ten lords a-leaping,",
        "Eleven pipers piping,","Twelve drummers drumming,"]

for i in range(0,11)
    print "On the " + days[i] + " day of Christmas,"
    print "my true love gave to me,"
    for j in range(i,0)
        print " " + gifts[j]
    end for
    print "     ----------"
end for
Output:
On the first day of Christmas,
my true love gave to me,
A partridge in a pear tree.
----------

<and so on until the last>

On the twelfth day of Christmas,
my true love gave to me,
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.
----------

Nim

Translation of: Python
import strutils, algorithm

const
  Gifts = ["A partridge in a pear tree.",
           "Two turtle doves",
           "Three french hens",
           "Four calling birds",
           "Five golden rings",
           "Six geese a-laying",
           "Seven swans a-swimming",
           "Eight maids a-milking",
           "Nine ladies dancing",
           "Ten lords a-leaping",
           "Eleven pipers piping",
           "Twelve drummers drumming"]

  Days = ["first", "second", "third", "fourth", "fifth", "sixth",
          "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]

for n, day in Days:
  var g = reversed(Gifts[0..n])
  echo "\nOn the ", day, " day of Christmas\nMy true love gave to me:\n",
       g[0..^2].join("\n"), if n > 0: " and\n" & g[^1] else: capitalizeAscii(g[^1])
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

Objeck

Translation of: C sharp – C#
class TwelveDaysOfChristmas  {
  function : Main(args : String[]) ~ Nil {
    days := ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
            "tenth", "eleventh", "twelfth"];
 
        gifts := ["A partridge in a pear tree",
            "Two turtle doves",
            "Three french hens",
            "Four calling birds",
            "Five golden rings",
            "Six geese a-laying",
            "Seven swans a-swimming",
            "Eight maids a-milking",
            "Nine ladies dancing",
            "Ten lords a-leaping",
            "Eleven pipers piping",
            "Twelve drummers drumming"];
 
        for(i := 0; i < days->Size(); i+=1;) {
          IO.Console->Print("On the ")->Print(days[i])->PrintLine(" day of Christmas, my true love gave to me");
		  
          j := i + 1;
          while(j > 0 ) {
            j -= 1;
            gifts[j]->PrintLine();
          };
      
           IO.Console->PrintLine();
 
           if (i = 0) {
             gifts[0] := "And a partridge in a pear tree";
           };
        };
    }
}

PARI/GP

days=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]; 
gifts=["And a partridge in a pear tree.", "Two turtle doves", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"];
{
for(i=1,#days,
  print("On the "days[i]" day of Christmas, my true love gave to me:");
  forstep(j=i,2,-1,print("\t"gifts[j]", "));
  print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
)
}
Output:
On the first day of Christmas, my true love gave to me:
        A partridge in a pear tree.
On the second day of Christmas, my true love gave to me:
        Two turtle doves,
        And a partridge in a pear tree.
[...]
On the twelfth day of Christmas, my true love gave to me:
        Twelve drummers drumming,
        Eleven pipers piping,
        Ten lords a-leaping,
        Nine ladies dancing,
        Eight maids a-milking,
        Seven swans a-swimming,
        Six geese a-laying,
        Five golden rings,
        Four calling birds,
        Three french hens,
        Two turtle doves,
        And a partridge in a pear tree.

Pascal

This should work with any modern Pascal implementation that has a string type, e.g. Free Pascal.

program twelve_days(output);

const
  days:  array[1..12] of string =
    ( 'first',   'second', 'third', 'fourth', 'fifth',    'sixth',
      'seventh', 'eighth', 'ninth', 'tenth',  'eleventh', 'twelfth' );

  gifts: array[1..12] of string =
    ( 'A partridge in a pear tree.',
      'Two turtle doves and',
      'Three French hens,',
      'Four calling birds,',
      'Five gold rings,',
      'Six geese a-laying,',
      'Seven swans a-swimming,',
      'Eight maids a-milking,',
      'Nine ladies dancing,',
      'Ten lords a-leaping,',
      'Eleven pipers piping,',
      'Twelve drummers drumming,' );

var
   day, gift: integer;

begin
   for day := 1 to 12 do begin
     writeln('On the ', days[day], ' day of Christmas, my true love sent to me:');
     for gift := day downto 1 do
       writeln(gifts[gift]);
     writeln
   end
end.
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Here's a version that works in ISO Standard Pascal, albeit with extraneous spaces in the output:

program twelve_days_iso(output);

const
  days:  array[1..12, 1..8] of char =
    ( 'first   ', 'second  ', 'third   ', 'fourth  ',
      'fifth   ', 'sixth   ', 'seventh ', 'eighth  ',
      'ninth   ', 'tenth   ', 'eleventh', 'twelfth ' );

  gifts: array[1..12, 1..27] of char =
    ( 'A partridge in a pear tree.',
      'Two turtle doves and       ',
      'Three French hens,         ',
      'Four calling birds,        ',
      'Five gold rings,           ',
      'Six geese a-laying,        ',
      'Seven swans a-swimming,    ',
      'Eight maids a-milking,     ',
      'Nine ladies dancing,       ',
      'Ten lords a-leaping,       ',
      'Eleven pipers piping,      ',
      'Twelve drummers drumming,  ' );

var
   day, gift: integer;

begin
   for day := 1 to 12 do begin
     writeln('On the ', days[day], ' day of Christmas, my true love gave to me:');
     for gift := day downto 1 do
       writeln(gifts[gift]);
     writeln
   end
end.
Output:
On the first    day of Christmas, my true love gave to me:
A partridge in a pear tree.

On the second   day of Christmas, my true love gave to me:
Two turtle doves and       
A partridge in a pear tree.

[...]

On the twelfth  day of Christmas, my true love gave to me:
Twelve drummers drumming,  
Eleven pipers piping,      
Ten lords a-leaping,       
Nine ladies dancing,       
Eight maids a-milking,     
Seven swans a-swimming,    
Six geese a-laying,        
Five gold rings,           
Four calling birds,        
Three French hens,         
Two turtle doves and       
A partridge in a pear tree.

Perl

use v5.10; 

my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };
 
chomp ( my @gifts = grep { /\S/ } <DATA> );

while ( my $day = shift @days ) {
    say "On the $day day of Christmas,\nMy true love gave to me:";
    say for map { $day eq 'first' ? s/And a/A/r : $_ } @gifts[@days .. @gifts-1];
    say "";
}

__DATA__
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.
Output:
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves
And a partridge in a pear tree.

...

On the twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.

Phix

constant days = {"first", "second", "third", "fourth", "fifth", "sixth",
                 "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"},
         gifts = {"A partridge in a pear tree.\n",
                  "Two turtle doves, and\n",
                  "Three French hens,\n",
                  "Four calling birds,\n",
                  "Five gold rings,\n",
                  "Six geese a-laying,\n",
                  "Seven swans a-swimming,\n",
                  "Eight maids a-milking,\n",
                  "Nine ladies dancing,\n",
                  "Ten lords a-leaping,\n",
                  "Eleven pipers piping,\n",
                  "Twelve drummers drumming,\n"}
for i=1 to 12 do
    printf(1,"On the %s day of Christmas,\nmy true love gave to me:\n",{days[i]})
    for j=i to 1 by -1 do
        printf(1,gifts[j])
    end for
end for

Phixmonti

include ..\Utilitys.pmt

( "A partridge in a pear tree."
  "Two turtle doves, and"
  "Three French hens,"
  "Four calling birds,"
  "Five gold rings,"
  "Six geese a-laying,"
  "Seven swans a-swimming,"
  "Eight maids a-milking,"
  "Nine ladies dancing,"
  "Ten lords a-leaping,"
  "Eleven pipers piping,"
  "Twelve drummers drumming," )

( "first" "second" "third" "fourth" "fifth" "sixth"
  "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth" )  
    
10 tochar var cr  
    
12 for >ps
    tps get
    "On the " swap " day of Christmas," cr "my true love gave to me:" 5 tolist lprint nl
    swap
    ( ps> 1 -1 ) for
        get ?
    endfor
    swap
    nl
endfor

PHP

<?php

header("Content-Type: text/plain; charset=UTF-8");

$days = array(
    'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
    'tenth', 'eleventh', 'twelfth',
);

$gifts = array(
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming"
);

$verses = [];

for ( $i = 0; $i < 12; $i++ ) {
    $lines = [];
    $lines[0] = "On the {$days[$i]} day of Christmas, my true love gave to me";
    
    $j = $i;
    $k = 0;
    while ( $j >= 0 ) {
        $lines[++$k] = $gifts[$j];
        $j--;
    }
        
    $verses[$i] = implode(PHP_EOL, $lines);
        
    if ( $i == 0 )
        $gifts[0] = "And a partridge in a pear tree";
}

echo implode(PHP_EOL . PHP_EOL, $verses);

?>

Or using recursion:

<?php

$gifts = array(
    'first'    => "A partridge in a pear tree",
    'second'   => "Two turtle doves",
    'third'    => "Three french hens",
    'fourth'   => "Four calling birds",
    'fifth'    => "Five golden rings",
    'sixth'    => "Six geese a-laying",
    'seventh'  => "Seven swans a-swimming",
    'eighth'   => "Eight maids a-milking",
    'ninth'    => "Nine ladies dancing",
    'tenth'    => "Ten lords a-leaping",
    'eleventh' => "Eleven pipers piping",
    'twelfth'  => "Twelve drummers drumming"
);

function print_day( $gifts ) {
    echo "On the ", key( $gifts ), " day of Xmas, my true love gave to me", PHP_EOL;
    foreach( $gifts as $day => $gift ) {
        echo $gift, $day == 'second' ? ' and' : '', PHP_EOL;
    }
    echo PHP_EOL;
}

function twelve_days( $gifts ) {
    if ( ! empty( $gifts ) ) {
        twelve_days( array_slice( $gifts, 1, null, true ) );
        print_day( $gifts );
    }
}

twelve_days( array_reverse( $gifts, true ) );
Output:
On the first day of Xmas, my true love gave to me
A partridge in a pear tree

On the second day of Xmas, my true love gave to me
Two turtle doves and
A partridge in a pear tree

On the third day of Xmas, my true love gave to me
Three french hens
Two turtle doves and
A partridge in a pear tree

On the fourth day of Xmas, my true love gave to me
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the fifth day of Xmas, my true love gave to me
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the sixth day of Xmas, my true love gave to me
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the seventh day of Xmas, my true love gave to me
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the eighth day of Xmas, my true love gave to me
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the ninth day of Xmas, my true love gave to me
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the tenth day of Xmas, my true love gave to me
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the eleventh day of Xmas, my true love gave to me
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

On the twelfth day of Xmas, my true love gave to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

Picat

List comprehension

go =>
  Days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split(" "),
  Gifts = 
"A partridge in a pear tree.
Two turtle doves, and
Three french hens,
Four calling birds,
Five golden rings,
Six geese a-laying,
Seven swans a-swimming,
Eight maids a-milking,
Nine ladies dancing,
Ten lords a-leaping,
Eleven pipers piping,
Twelve drummers drumming,".split("\n"),

  println([to_fstring("On the %s day of Christmas,\nMy true love gave to me:\n%w\n", 
           Day, slice(Gifts,1,D).reverse().join("\n")) : {Day,D} in zip(Days,1..length(Days))]
           .join("\n")),
  nl.

Definite clause grammars (DCG)

go2 ?=>
  lyrics(Ls,[]),
  println(Ls.flatten),  
  nl.
go2 => true.

lyrics -->
        { Days = findall(D, $day(D,_,[])) },       
        stanzas(Days, []).

stanzas([], _) --> [].
stanzas([Day|Days], Prevs) -->
        "On the ", [Day.to_string], " day of Christmas\n", % convert atom day to string
        "My true love gave to me:\n",
        day(Day), 
        previous_days(Prevs),
        "\n\n",
        stanzas(Days, [Day|Prevs]).

previous_days([]) --> [].
previous_days([D|Ds]) --> previous_days_(Ds, D).

previous_days_([], D) --> " and\n", day(D).
previous_days_([D|Ds], Prev) --> "\n",
        day(Prev),
        previous_days_(Ds, D).

day(first)    --> "A partridge in a pear tree.".
day(second)   --> "Two turtle doves".
day(third)    --> "Three french hens".
day(fourth)   --> "Four calling birds".
day(fifth)    --> "Five golden rings".
day(sixth)    --> "Six geese a-laying".
day(seventh)  --> "Seven swans a-swimming".
day(eight)    --> "Eight maids a-milking".
day(ninth)    --> "Nine ladies dancing".
day(tenth)    --> "Ten lords a-leaping".
day(eleventh) --> "Eleven pipers piping".
day(twelth)   --> "Twelve drummers drumming".

PicoLisp

(de days
   first second third fourth fifth sixth
   seventh eight ninth tenth eleventh twelfth )

(de texts
   "A partridge in a pear tree."
   "Two turtle doves and"
   "Three french hens"
   "Four calling birds"
   "Five golden rings"
   "Six geese a-laying"
   "Seven swans a-swimming"
   "Eight maids a-milking"
   "Nine ladies dancing"
   "Ten lords a-leaping"
   "Eleven pipers piping"
   "Twelve drummers drumming" )

(for (X . Day) days
   (prinl "On the " Day " day of Christmas")
   (prinl "My true love game to me:")
   (for (Y X (gt0 Y) (dec Y))
      (prinl
         (if (and (= 12 X) (= 1 Y))
            "And a partridge in a pear tree."
            (get texts Y)) ) )
   (prinl) )

(bye)

Pike

int main() {
	array(string) days = ({"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"});
	array(string) gifts = ({"A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"});

	for (int i = 0; i < 12; i++) {
		write("On the " + (string)days[i] + " day of Christmas\n");
		write("My true love gave to me:\n");
		for (int j = 0; j < i + 1; j++) {
			write((string)gifts[i - j] + "\n");
		}
		if (i != 11) {
			write("\n");
		}
	}
	return 0;
}
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

Pointless

output =
  range(1, 12)
  |> map(makeVerse)
  |> join("\n\n")
  |> print

days = {
  1: "first",
  2: "second",
  3: "third",
  4: "fourth",
  5: "fifth",
  6: "sixth",
  7: "seventh",
  8: "eighth",
  9: "ninth",
  10: "tenth",
  11: "eleventh",
  12: "twelfth"
}

verseFormat = """On the {} day of Christmas
My true love gave to me:
{}"""

makeVerse(n) =
  format(verseFormat,
  [getDefault(days, "", n),
  makeGifts(n)])

gifts = [
  "A partridge in a pear tree.",
  "Two turtle doves and",
  "Three french hens",
  "Four calling birds",
  "Five golden rings",
  "Six geese a-laying",
  "Seven swans a-swimming",
  "Eight maids a-milking",
  "Nine ladies dancing",
  "Ten lords a-leaping",
  "Eleven pipers piping",
  "Twelve drummers drumming",
]

makeGifts(n) =
  gifts
  |> take(n)
  |> reverse
  |> join("\n")

PowerShell

$days = @{
    1 = "first";
    2 = "second";
    3 = "third";
    4 = "fourth";
    5 = "fifth";
    6 = "sixth";
    7 = "seventh";
    8 = "eight";
    9 = "ninth";
    10 = "tenth";
    11 = "eleventh";
    12 = "twelfth";
}

$gifts = @{
    1 = 'A partridge in a pear tree';
    2 = 'Two turtle doves';
    3 = 'Three french hens';
    4 = 'Four calling birds';
    5 = 'Five golden rings';
    6 = 'Six geese a-laying';
    7 = 'Seven swans a-swimming';
    8 = 'Eight maids a-milking';
    9 = 'Nine ladies dancing';
    10 = 'Ten lords a-leaping';
    11 = 'Eleven pipers piping';
    12 = 'Twelve drummers drumming';
}

1 .. 12 | % {
    "On the $($days[$_]) day of Christmas`nMy true love gave to me"
    $_ .. 1 | % { 
        $gift = $gifts[$_]
        if ($_ -eq 2) { $gift += " and" }
        $gift
    }
    ""
}
Output:
On the first day of Christmas
My true love gave to me
A partridge in a pear tree

On the second day of Christmas
My true love gave to me
Two turtle doves and
A partridge in a pear tree

...

On the twelfth day of Christmas
My true love gave to me
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree

Prog8

%zeropage basicsafe
%import textio

main {
    str[12] ordinals = [ "first", "second", "third",    "fourth",
                         "fifth", "sixth",  "seventh",  "eighth",
                         "ninth", "tenth",  "eleventh", "twelfth" ]

    str[12] gifts = [ "A partridge in a pear tree.",
                      "Two turtle doves and",
                      "Three French hens,",
                      "Four calling birds,",
                      "Five gold rings,", 
                      "Six geese a-laying,",
                      "Seven swans a-swimming,",
                      "Eight maids a-milking,",
                      "Nine ladies dancing,",
                      "Ten lords a-leaping,",
                      "Eleven pipers piping,",
                      "Twelve drummers drumming," ]

    sub print_gifts(ubyte day) {
        ubyte i
        txt.print("On the ")
        txt.print(ordinals[day])
        txt.print(" day of Christmas, my true love sent to me:")
        txt.nl()
        for i in day to 0 step -1 {
            txt.print(gifts[i])
            txt.nl()
        }
    }

    sub start() {
        ubyte day

        txt.lowercase()
        for day in 0 to 11 {
            txt.nl()
            print_gifts(day)
        }
    }
}
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[ ... ]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Prolog

day(1, 'first').
day(2, 'second').
day(3, 'third').
day(4, 'fourth').
day(5, 'fifth').
day(6, 'sixth').
day(7, 'seventh').
day(8, 'eighth').
day(9, 'ninth').
day(10, 'tenth').
day(11, 'eleventh').
day(12, 'twelfth').

gift(1, 'A partridge in a pear tree.').
gift(2, 'Two turtle doves and').
gift(3, 'Three French hens,').
gift(4, 'Four calling birds,').
gift(5, 'Five gold rings,').
gift(6, 'Six geese a-laying,').
gift(7, 'Seven swans a-swimming,').
gift(8, 'Eight maids a-milking,').
gift(9, 'Nine ladies dancing,').
gift(10, 'Ten lords a-leaping,').
gift(11, 'Eleven pipers piping,').
gift(12, 'Twelve drummers drumming,').

giftsFor(0, []) :- !.
giftsFor(N, [H|T]) :- gift(N, H), M is N-1, giftsFor(M,T).

writeln(S) :- write(S), write('\n').

writeList([])    :- writeln(''), !.
writeList([H|T]) :- writeln(H), writeList(T).

writeGifts(N) :- day(N, Nth), write('On the '), write(Nth),
    writeln(' day of Christmas, my true love sent to me:'),
    giftsFor(N,L), writeList(L).

writeLoop(0) :- !.
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).

main :- writeLoop(12), halt.
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[ ... ]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

PureBasic

#TXT$ = "On the * day of Christmas, my true love sent to me:"
days$ = ~"first\nsecond\nthird\nfourth\nfifth\nsixth\nseventh\neighth\nninth\ntenth\neleventh\ntwelfth\n"
gifts$= ~"Twelve drummers drumming,\nEleven pipers piping,\nTen lords a-leaping,\nNine ladies dancing,\n"+
        ~"Eight maids a-milking,\nSeven swans a-swimming,\nSix geese a-laying,\nFive golden rings,\n"+
        ~"Four calling birds,\nThree french hens,\nTwo turtle doves,\nA partridge in a pear tree.\n"
Define  I.i, J.i

If OpenConsole("The twelve days of Christmas")
  For I = 1 To 12
    PrintN(ReplaceString(#TXT$,"*",StringField(days$,I,~"\n")))    
    For J = 13-I To 12      
      PrintN(" -> "+StringField(gifts$,J,~"\n"))
    Next J    
  Next I
  Input()
EndIf
Output:
On the first day of Christmas, my true love sent to me:
 -> A partridge in a pear tree.
On the second day of Christmas, my true love sent to me:
 -> Two turtle doves,
 -> A partridge in a pear tree.
.
.
.
On the eleventh day of Christmas, my true love sent to me:
 -> Eleven pipers piping,
 -> Ten lords a-leaping,
 -> Nine ladies dancing,
 -> Eight maids a-milking,
 -> Seven swans a-swimming,
 -> Six geese a-laying,
 -> Five golden rings,
 -> Four calling birds,
 -> Three french hens,
 -> Two turtle doves,
 -> A partridge in a pear tree.
On the twelfth day of Christmas, my true love sent to me:
 -> Twelve drummers drumming,
 -> Eleven pipers piping,
 -> Ten lords a-leaping,
 -> Nine ladies dancing,
 -> Eight maids a-milking,
 -> Seven swans a-swimming,
 -> Six geese a-laying,
 -> Five golden rings,
 -> Four calling birds,
 -> Three french hens,
 -> Two turtle doves,
 -> A partridge in a pear tree.

Python

gifts = '''\
A partridge in a pear tree.
Two turtle doves
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leaping
Eleven pipers piping
Twelve drummers drumming'''.split('\n')

days = '''first second third fourth fifth
          sixth seventh eighth ninth tenth
          eleventh twelfth'''.split()

for n, day in enumerate(days, 1):
    g = gifts[:n][::-1]
    print(('\nOn the %s day of Christmas\nMy true love gave to me:\n' % day) +
          '\n'.join(g[:-1]) +
          (' and\n' + g[-1] if n > 1 else g[-1].capitalize()))
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

On the third day of Christmas
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree.

On the fourth day of Christmas
My true love gave to me:
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.
.
.
.

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

q

DAYS:" "vs"first second third fourth fifth sixth",
  " seventh eighth ninth tenth eleventh twelfth"

STANZA:(                              / final stanza
  "On the twelfth day of Christmas";
  "My true love gave to me:";
  "Twelve drummers drumming";
  "Eleven pipers piping";
  "Ten lords a-leaping";
  "Nine ladies dancing";
  "Eight maids a-milking";
  "Seven swans a-swimming";
  "Six geese a-laying";
  "Five golden rings";
  "Four calling birds";
  "Three french hens";
  "Two turtle doves";
  "And a partridge in a pear tree.";
  "")

-1 raze 
  .[;0 2;"A",5_]                         / tweak one line
  .[;(::;0);ssr[;"twelfth";];DAYS]       / number the verses
  STANZA 0 1,/:#\:[;til 15] -2 -til 12;  / compose 12 verses
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves
And a partridge in a pear tree.

..

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.

Quackery

  [ [ table
      $ "first" $ "second" $ "third"    $ "fourth"
      $ "fifth" $ "sixth"  $ "seventh"  $ "eighth"
      $ "ninth" $ "tenth"  $ "eleventh" $ "twelfth" ]
    do echo$ ]                                        is day   ( n --> )  
 
  [ [ table
      $ "A partridge in a pear tree."
      $ "Two turtle doves and"
      $ "Three French hens,"
      $ "Four calling birds,"
      $ "Five gold rings,"
      $ "Six geese a-laying,"
      $ "Seven swans a-swimming,"
      $ "Eight maids a-milking,"
      $ "Nine ladies dancing,"
      $ "Ten lords a-leaping,"
      $ "Eleven pipers piping,"
      $ "Twelve drummers drumming," ] do echo$ ]      is gift  ( n --> )
      
  [ say "On the " dup day say " day of Christmas," cr
    say "My true love gave to me," cr
    1+ times [ i gift cr ] cr ]                       is verse ( n --> )

  [  12 times [ i^ verse ] ]                          is song  (   --> )
  
  song
Output:
On the first day of Christmas,
My true love gave to me,
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me,
Two turtle doves and
A partridge in a pear tree.

[ ... ]

On the twelfth day of Christmas,
My true love gave to me,
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.


R

gifts <- c("A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming")
days <- c("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth")

for (i in seq_along(days)) {
  cat("On the", days[i], "day of Christmas\n")
  cat("My true love gave to me:\n")
  cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}
Output:
## On the first day of Christmas
## My true love gave to me:
## A partridge in a pear tree. 
## 
## On the second day of Christmas
## My true love gave to me:
## Two turtle doves and
## A partridge in a pear tree. 
## 
## On the third day of Christmas
## My true love gave to me:
## Three french hens
## Two turtle doves and
## A partridge in a pear tree. 
## 
## On the fourth day of Christmas
## My true love gave to me:
## Four calling birds
## Three french hens
## Two turtle doves and
## A partridge in a pear tree. 
## 
...
## 
## On the twelfth day of Christmas
## My true love gave to me:
## Twelve drummers drumming
## Eleven pipers piping
## Ten lords a-leaping
## Nine ladies dancing
## Eight maids a-milking
## Seven swans a-swimming
## Six geese a-laying
## Five golden rings
## Four calling birds
## Three french hens
## Two turtle doves and
## A partridge in a pear tree.

Racket

This version:

  • doesn't capitalise the word Twelfth
  • capitalises the French   (in French hen)
  • capitalised True Love as it may save me a lot of grief when I get home.
  • British Variant: changes golden to go-old rings. Anyone who still has enough breath left to sing the second syllable after sustaining the first syllable of golden simply wasn't making enough effort in the first place.
  • British Variant: capitalises FIVE GO-OLD RINGS since it needs to be sung at top volume. If you want to change this back; the source is there. But I guarantee you won't have as much fun singing it.
#lang racket
(define (ordinal-text d)
  (vector-ref
   (vector
    "zeroth" "first" "second" "third" "fourth"
    "fifth" "sixth" "seventh" "eighth" "ninth"
    "tenth" "eleventh" "twelfth")
   d))

(define (on-the... day)
  (printf "On the ~a day of Christmas,~%" (ordinal-text day))
  (printf "My True Love gave to me,~%"))

(define (prezzy prezzy-line day)  
  (match prezzy-line
    [1 (string-append (if (= day 1) "A " "And a")" partridge in a pear tree")]
    [2 "Two turtle doves"]
    [3 "Three French hens"]
    [4 "Four calling birds"]
    [5 "FIVE GO-OLD RINGS"]
    [6 "Six geese a-laying"]
    [7 "Seven swans a-swimming"]
    [8 "Eight maids a-milking"]
    [9 "Nine ladies dancing"]
    [10 "Ten lords a-leaping"]
    [11 "Eleven pipers piping"]
    [12 "Twelve drummers drumming"]))

(define (line-end prezzy-line day)  
  (match* (day prezzy-line) [(12 1) "."] [(x 1) ".\n"] [(_ _) ","]))

(for ((day (sequence-map add1 (in-range 12)))
      #:when (on-the... day)
      (prezzy-line (in-range day 0 -1)))
  (printf "~a~a~%" (prezzy prezzy-line day) (line-end prezzy-line day)))
Output:
On the first day of Christmas,
My True Love gave to me,
A  partridge in a pear tree.

On the second day of Christmas,
My True Love gave to me,
Two turtle doves,
And a partridge in a pear tree.

On the third day of Christmas,
My True Love gave to me,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the fourth day of Christmas,
My True Love gave to me,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the fifth day of Christmas,
My True Love gave to me,
FIVE GO-OLD RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the sixth day of Christmas,
My True Love gave to me,
Six geese a-laying,
FIVE GO-OLD RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

On the seventh day of Christmas, ...
On the eighth day of Christmas, ...
On the ninth day of Christmas, ...
On the tenth day of Christmas, ...
On the eleventh day of Christmas, ...

On the twelfth day of Christmas,
My True Love gave to me,
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
FIVE GO-OLD RINGS,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

Raku

(formerly Perl 6)

my @days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;

my @gifts = lines q:to/END/;
  And a partridge in a pear tree.
  Two turtle doves,
  Three french hens,
  Four calling birds,
  Five golden rings,
  Six geese a-laying,
  Seven swans a-swimming,
  Eight maids a-milking,
  Nine ladies dancing,
  Ten lords a-leaping,
  Eleven pipers piping,
  Twelve drummers drumming,
END

sub nth($n) { say "On the @days[$n] day of Christmas, my true love gave to me:" }

nth(0);
say @gifts[0].subst('And a','A');

for 1 ... 11 -> $d {
    say '';
    nth($d);
    say @gifts[$_] for $d ... 0;
}
Output:
On the first day of Christmas, my true love gave to me:
  A partridge in a pear tree.

On the second day of Christmas, my true love gave to me:
  Two turtle doves,
  And a partridge in a pear tree.

On the third day of Christmas, my true love gave to me:
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.

On the fourth day of Christmas, my true love gave to me:
  Four calling birds,
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.
.
.
.
On the twelfth day of Christmas, my true love gave to me:
  Twelve drummers drumming,
  Eleven pipers piping,
  Ten lords a-leaping,
  Nine ladies dancing,
  Eight maids a-milking,
  Seven swans a-swimming,
  Six geese a-laying,
  Five golden rings,
  Four calling birds,
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.

REXX

This version:

  •   doesn't capitalize the word   Twelfth
  •   capitalizes the   French   (in French hen)
  •   capitalized   True Love   as it (may) refer to a deity
  •   added indentation to make verses resemble song lyrics
/*REXX program displays the verses of the song:    "The 12 days of Christmas".          */
ordD= 'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
pad= left('', 20)                                /*used for indenting the shown verses. */
                   @.1= 'A partridge in a pear-tree.';   @.7 = "Seven swans a-swimming,"
                   @.2= 'Two Turtle Doves, and'      ;   @.8 = "Eight maids a-milking,"
                   @.3= 'Three French Hens,'         ;   @.9 = "Nine ladies dancing,"
                   @.4= 'Four Calling Birds,'        ;   @.10= "Ten lords a-leaping,"
                   @.5= 'Five Golden Rings,'         ;   @.11= "Eleven pipers piping,"
                   @.6= 'Six geese a-laying,'        ;   @.12= "Twelve drummers drumming,"
  do day=1  for 12
  say pad  'On the'   word(ordD, day)   "day of Christmas"    /*display line 1 prologue.*/
  say pad  'My True Love gave to me:'                         /*   "      "  2     "    */
              do j=day  by -1  to 1;       say pad @.j        /*   "    the daily gifts.*/
              end   /*j*/
  say                                            /*add a blank line between the verses. */
  end               /*day*/                      /*stick a fork in it,  we're all done. */
output:


(Shown at three-quarters size.)

                     On the first day of Christmas
                     My True Love gave to me:
                     A partridge in a pear-tree.

                     On the second day of Christmas
                     My True Love gave to me:
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the third day of Christmas
                     My True Love gave to me:
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the fourth day of Christmas
                     My True Love gave to me:
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the fifth day of Christmas
                     My True Love gave to me:
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the sixth day of Christmas
                     My True Love gave to me:
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the seventh day of Christmas
                     My True Love gave to me:
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the eighth day of Christmas
                     My True Love gave to me:
                     Eight maids a-milking,
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the ninth day of Christmas
                     My True Love gave to me:
                     Nine ladies dancing,
                     Eight maids a-milking,
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the tenth day of Christmas
                     My True Love gave to me:
                     Ten lords a-leaping,
                     Nine ladies dancing,
                     Eight maids a-milking,
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the eleventh day of Christmas
                     My True Love gave to me:
                     Eleven pipers piping,
                     Ten lords a-leaping,
                     Nine ladies dancing,
                     Eight maids a-milking,
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the twelfth day of Christmas
                     My True Love gave to me:
                     Twelve drummers drumming,
                     Eleven pipers piping,
                     Ten lords a-leaping,
                     Nine ladies dancing,
                     Eight maids a-milking,
                     Seven swans a-swimming,
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

Ring

# Project : The Twelve Days of Christmas

gifts = "A partridge in a pear tree,Two turtle doves,Three french hens,Four calling birds,Five golden rings,Six geese a-laying,Seven swans a-swimming,Eight maids a-milking,Nine ladies dancing,Ten lords a-leaping,Eleven pipers piping,Twelve drummers drumming"
days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
lstgifts = str2list(substr(gifts,",", nl))
lstdays = str2list(substr(days, " ", nl))
for i = 1 to 12
     see "On the "+ lstdays[i]+ " day of Christmas" + nl
     see "My true love gave to me:" + nl
     for j = i to 1 step -1
          if i > 1 and j = 1
             see "and " + nl
          ok
          see "" + lstgifts[j] + nl
     next
     see nl
next

Output:

On the first day of Christmas
My true love gave to me:
A partridge in a pear tree

On the second day of Christmas
My true love gave to me:
Two turtle doves
and 
A partridge in a pear tree

On the third day of Christmas
My true love gave to me:
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the fourth day of Christmas
My true love gave to me:
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the fifth day of Christmas
My true love gave to me:
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the sixth day of Christmas
My true love gave to me:
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the seventh day of Christmas
My true love gave to me:
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the eighth day of Christmas
My true love gave to me:
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the ninth day of Christmas
My true love gave to me:
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the tenth day of Christmas
My true love gave to me:
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the eleventh day of Christmas
My true love gave to me:
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and 
A partridge in a pear tree

Ruby

gifts = "A partridge in a pear tree
Two turtle doves and
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leaping
Eleven pipers piping
Twelve drummers drumming".split("\n")

days = %w(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)

days.each_with_index do |day, i| 
  puts "On the #{day} day of Christmas"
  puts "My true love gave to me:"
  puts gifts[0, i+1].reverse
  puts
end

Run BASIC

gifts$ = "
A partridge in a pear tree.,
Two turtle doves,
Three french hens,
Four calling birds,
Five golden rings,
Six geese a-laying,
Seven swans a-swimming,
Eight maids a-milking,
Nine ladies dancing,
Ten lords a-leaping,
Eleven pipers piping,
Twelve drummers drumming"
 
days$ = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
 
for i = 1 to 12
    print "On the ";word$(days$,i," ");" day of Christmas"
    print "My true love gave to me:"
    for j = i to 1 step -1
    if i > 1 and j = 1 then print "and ";
    print mid$(word$(gifts$,j,","),2)
    next j
    print
next i

Output:

On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.
.
.
On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
and A partridge in a pear tree.

Rust

Rust Playground

fn main() {
    let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
                "ninth", "tenth", "eleventh", "twelfth"];

    let gifts = ["A Partridge in a Pear Tree",
                 "Two Turtle Doves and",
                 "Three French Hens",
                 "Four Calling Birds",
                 "Five Golden Rings",
                 "Six Geese a Laying",
                 "Seven Swans a Swimming",
                 "Eight Maids a Milking",
                 "Nine Ladies Dancing",
                 "Ten Lords a Leaping",
                 "Eleven Pipers Piping",
                 "Twelve Drummers Drumming"];

    for i in 0..12 {
        println!("On the {} day of Christmas,", days[i]);
        println!("My true love gave to me:");

        for j in (0..i + 1).rev() {
            println!("{}", gifts[j]);
        }
        println!()
    }
}

Scala

val gifts = Array(
    "A partridge in a pear tree.",
    "Two turtle doves and",
    "Three French hens,",
    "Four calling birds,",
    "Five gold rings,",
    "Six geese a-laying,",
    "Seven swans a-swimming,",
    "Eight maids a-milking,",
    "Nine ladies dancing,",
    "Ten lords a-leaping,",
    "Eleven pipers piping,",
    "Twelve drummers drumming,"
  )

val days = Array(
    "first",   "second", "third", "fourth", "fifth",    "sixth",
    "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth"
  )

val giftsForDay = (day: Int) =>
    "On the %s day of Christmas, my true love sent to me:\n".format(days(day)) +
      gifts.take(day+1).reverse.mkString("\n") + "\n"

(0 until 12).map(giftsForDay andThen println)
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Scheme

Without Common Lisp's format, we sadly have to hard-code the list of ordinals.

; Racket has this built in, but it's not standard
(define (take lst n)
  (if (or (null? lst) (<= n 0))
      '()
      (cons (car lst) (take (cdr lst) (- n 1)))))

(let
  ((days  '("first" "second" "third" "fourth" "fifth" "sixth" "seventh"
            "eighth" "ninth" "tenth" "eleventh" "twelfth"))

   (gifts '("A partridge in a pear tree." "Two turtle doves, and"
            "Three French hens,"          "Four calling birds,"
            "Five gold rings,"            "Six geese a-laying,"
            "Seven swans a-swimming,"     "Eight maids a-milking,"
            "Nine ladies dancing,"        "Ten lords a-leaping,"
            "Eleven pipers piping,"       "Twelve drummers drumming,")))

  (do ((left days (cdr left))
       ; No universal predefined (+ 1) function, sadly. Implementations
       ; are divided between (add1) and (1+).
       (day  1    (+ 1 day))) 
      ((null? left) #t)

    (display "On the ")
    (display (car left))
    (display " day of Christmas, my true love sent to me:")
    (newline)

    (do ((daily (reverse (take gifts day)) (cdr daily)))
        ((null? daily) #t)

      (display (car daily))
      (newline))
      (newline)))

(exit)
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.

Seed7

$ include "seed7_05.s7i";

const proc: main is func
  local
    const array string: gifts is [] (
        "A partridge in a pear tree.", "Two turtle doves and",
        "Three french hens", "Four calling birds",
        "Five golden rings", "Six geese a-laying",
        "Seven swans a-swimming", "Eight maids a-milking",
        "Nine ladies dancing", "Ten lords a-leaping",
        "Eleven pipers piping", "Twelve drummers drumming");
    const array string: days is [] (
        "first", "second", "third", "fourth", "fifth", "sixth",
        "seventh", "eighth", "ninth", "tenth", "eleventh", "Twelfth");
    var integer: day is 0;
    var integer: gift is 0;
  begin
    for day range 1 to length(days) do
      writeln;
      writeln("On the " <& days[day] <& " day of Christmas,");
      writeln("My true love gave to me:");
      for gift range day downto 1 do
        writeln(gifts[gift]);
      end for;
    end for;
  end func;
Output:
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

On the third day of Christmas,
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree.

...

On the Twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

Self

Nicely factored:

(|
parent* = traits oddball.

gifts = (
   'And a partridge in a pear tree' &
   'Two turtle doves' &
   'Three french hens' &
   'Four calling birds' &
   'FIVE GO-OLD RINGS' &
   'Six geese a-laying' &
   'Seven swans a-swimming' &
   'Eight maids a-milking' &
   'Nine ladies dancing' &
   'Ten lords a-leaping' &
   'Eleven pipers piping' &
   'Twelve drummers drumming'
) asSequence.

days = (
   'first' & 'second' & 'third'    & 'fourth'  & 
   'fifth' & 'sixth'  & 'seventh'  & 'eighth'  &
   'ninth' & 'tenth'  & 'eleventh' & 'twelfth'
) asSequence.

intro: i = ( 'On the ', (days at: i), ' day of Christmas, my true love gave to me:').
gifts: i = (  i = 0 ifTrue: [sequence copyAddFirst: 'A partridge in a pear tree' ]
                     False: [(gifts slice: 0@(i + 1)) reverse ]).
verse: i = ( ((sequence copyAddFirst: intro: i) addAll: gifts: i) addLast: '' ).
value    = ( (days gather: [|:d. :i| verse: i ]) asSequence joinUsing: '\n' )

|) value printLine

SenseTalk

put [
	"partridge in a pear tree.",
	"turtle doves and",
	"french hens",
	"calling birds",
	"golden rings",
	"geese a-laying",
	"swans a-swimming",
	"maids a-milking",
	"ladies dancing",
	"lords a-leaping",
	"pipers piping",
	"drummers drumming"
] into gifts

repeat with each item d1 of 1 .. 12
	put "On the" && ordinalwords of d1 && "day of Christmas,"
	put "My true love gave to me:"
	repeat with each item d2 of d1 .. 1
		if d2 is 1
			put "A" into number
		else
			put capitalized(numberwords of d2) into number 
		end if
		put number && item d2 of gifts		
	end repeat
	put ""
end repeat
Output:
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

On the third day of Christmas,
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

SETL

program christmas;
    ordinals := [
        "first", "second", "third", "fourth", "fifth",
        "sixth", "seventh", "eight", "ninth", "tenth",
        "eleventh", "twelfth"
    ];
    
    verses := [
        "A partridge in a pear tree.",
        "Two turtle doves and",
        "Three french hens",
        "Four calling birds",
        "Five golden rings",
        "Six geese a-laying",
        "Seven swans a-swimming",
        "Eight maids a-milking",
        "Nine ladies dancing",
        "Ten lords a-leaping",
        "Eleven pipers piping",
        "Twelve drummers drumming"
    ];
    
    loop for i in [1..12] do
        print("On the " + ordinals(i) + " day of Christmas,");
        print("My true love gave to me");
        loop for j in [i, i-1..1] do
            print(verses(j));
        end loop;
        print;
    end loop;
end program;

Sidef

Translation of: Raku
var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;

var gifts = <<'EOT'.lines;
  And a partridge in a pear tree.
  Two turtle doves,
  Three french hens,
  Four calling birds,
  Five golden rings,
  Six geese a-laying,
  Seven swans a-swimming,
  Eight maids a-milking,
  Nine ladies dancing,
  Ten lords a-leaping,
  Eleven pipers piping,
  Twelve drummers drumming,
EOT

func nth(n) { say "On the #{days[n]} day of Christmas, my true love gave to me:" };

nth(0);
say gifts[0].sub('And a', 'A');

range(1, 11).each { |d|
    say '';
    nth(d);
    d.downto(0).each { |i|
        say gifts[i];
    }
}
Output:
On the first day of Christmas, my true love gave to me:
  A partridge in a pear tree.

On the second day of Christmas, my true love gave to me:
  Two turtle doves,
  And a partridge in a pear tree.

On the third day of Christmas, my true love gave to me:
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.

On the fourth day of Christmas, my true love gave to me:
  Four calling birds,
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.
.
.
.
On the twelfth day of Christmas, my true love gave to me:
  Twelve drummers drumming,
  Eleven pipers piping,
  Ten lords a-leaping,
  Nine ladies dancing,
  Eight maids a-milking,
  Seven swans a-swimming,
  Six geese a-laying,
  Five golden rings,
  Four calling birds,
  Three french hens,
  Two turtle doves,
  And a partridge in a pear tree.

Simula

Works with: GNU Cim
Begin
  Text Array days(1:12), gifts(1:12);
  Integer day, gift;

  days(1)  :- "first";
  days(2)  :- "second";
  days(3)  :- "third";
  days(4)  :- "fourth";
  days(5)  :- "fifth";
  days(6)  :- "sixth";
  days(7)  :- "seventh";
  days(8)  :- "eighth";
  days(9)  :- "ninth";
  days(10) :- "tenth";
  days(11) :- "eleventh";
  days(12) :- "twelfth";


  gifts(1)  :- "A partridge in a pear tree.";
  gifts(2)  :- "Two turtle doves and";
  gifts(3)  :- "Three French hens,";
  gifts(4)  :- "Four calling birds,";
  gifts(5)  :- "Five gold rings,";
  gifts(6)  :- "Six geese a-laying,";
  gifts(7)  :- "Seven swans a-swimming,";
  gifts(8)  :- "Eight maids a-milking,";
  gifts(9)  :- "Nine ladies dancing,";
  gifts(10) :- "Ten lords a-leaping,";
  gifts(11) :- "Eleven pipers piping,";
  gifts(12) :- "Twelve drummers drumming,";

  For day := 1 Step 1 Until 12 Do Begin
    outtext("On the "); outtext(days(day)); 
    outtext(" day of Christmas, my true love sent to me:"); outimage;
    For gift := day Step -1 Until 1 Do Begin
      outtext(gifts(gift)); outimage
    End;
    outimage
  End
End
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Smalltalk

Works with: GNU Smalltalk
Object subclass: TwelveDays [
  Ordinals := #('first'   'second' 'third' 'fourth' 'fifth'    'sixth'
                'seventh' 'eighth' 'ninth' 'tenth'  'eleventh' 'twelfth').

  Gifts := #( 'A partridge in a pear tree.' 'Two turtle doves and'
              'Three French hens,'          'Four calling birds,'
              'Five gold rings,'            'Six geese a-laying,'
              'Seven swans a-swimming,'     'Eight maids a-milking,'
              'Nine ladies dancing,'        'Ten lords a-leaping,'
              'Eleven pipers piping,'       'Twelve drummers drumming,' ).
]

TwelveDays class extend [
  giftsFor: day [
    |newLine ordinal giftList|
    newLine := $<10> asString.
    ordinal := Ordinals at: day.
    giftList := (Gifts first: day) reverse.

    ^'On the ', ordinal, ' day of Christmas, my true love sent to me:',
      newLine, (giftList join: newLine), newLine.
  ]
]

1 to: 12 do: [:i |
  Transcript show: (TwelveDays giftsFor: i); cr.
].
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Smart BASIC

' by rbytes
dim d$(12),x$(15)!s=15
for t=0 to 11!read d$(t)!next t
for t=0 to 14!read x$(t)!next t
for u=0 to 11!s-=1
print x$(0)&d$(u)&x$(1)&chr$(10)&x$(2)
for t=s to 14!print x$(t)!next t
print!next u!data "first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","Twelfth","On the "," day of Christmas","My true love gave to me:","Twelve drummers drumming","Eleven pipers piping","Ten lords a-leaping","Nine ladies dancing","Eight maids a-milking","Seven swans a-swimming,","Six geese a-laying","Five golden rings","Four calling birds","Three french hens","Two turtle doves and","A partridge in a pear tree."
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

On the third day of Christmas
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree.

[ ... ]

On the eleventh day of Christmas
My true love gave to me:
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming,
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

On the Twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming,
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves and
A partridge in a pear tree.

Snobol

Works with: CSNOBOL4
	DAYS = ARRAY('12')
	DAYS<1> = 'first'
	DAYS<2> = 'second'
	DAYS<3> = 'third'
	DAYS<4> = 'fourth'
	DAYS<5> = 'fifth'
	DAYS<6> = 'sixth'
	DAYS<7> = 'seventh'
	DAYS<8> = 'eighth'
	DAYS<9> = 'ninth'
	DAYS<10> = 'tenth'
	DAYS<11> = 'eleventh'
	DAYS<12> = 'twelfth'

	GIFTS = ARRAY('12')
	GIFTS<1> = 'A partridge in a pear tree.'
	GIFTS<2> = 'Two turtle doves and'
	GIFTS<3> = 'Three French hens,'
	GIFTS<4> = 'Four calling birds,'
	GIFTS<5> = 'Five gold rings,'
	GIFTS<6> = 'Six geese a-laying,'
	GIFTS<7> = 'Seven swans a-swimming,'
	GIFTS<8> = 'Eight maids a-milking,'
	GIFTS<9> = 'Nine ladies dancing,'
	GIFTS<10> = 'Ten lords a-leaping,'
	GIFTS<11> = 'Eleven pipers piping,'
	GIFTS<12> = 'Twelve drummers drumming,'

       DAY = 1
OUTER  LE(DAY,12)            :F(END)
       INTRO = 'On the NTH day of Christmas, my true love sent to me:'
       INTRO 'NTH' = DAYS<DAY>
       OUTPUT = INTRO
       GIFT = DAY
INNER  GE(GIFT,1)            :F(NEXT)
       OUTPUT = GIFTS<GIFT>
       GIFT = GIFT - 1       :(INNER)
NEXT   OUTPUT = ''
       DAY = DAY + 1         :(OUTER)
END
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

SparForte

As a structured script.

#!/usr/local/bin/spar
pragma annotate( summary, "twelve_days" )
       @( description, "Write a program that outputs the lyrics of the " )
       @( description, "Christmas carol The Twelve Days of Christmas. " )
       @( see_also, "http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas" );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );

pragma restriction( no_external_commands );

procedure twelve_days is
  type days is ( first, second, third, forth, fifth, sixth,seventh, eighth,
                 ninth, tenth, eleventh, twelfth );
  gifts : array( first..twelfth ) of string := (
          " A partridge in a pear-tree.",
          " Two turtle doves",
          " Three French hens",
          " Four calling birds",
          " Five golden rings",
          " Six geese a-laying",
          " Seven swans a-swimming",
          " Eight maids a-milking",
          " Nine ladies dancing",
          " Ten lords a-leaping",
          " Eleven pipers piping",
          " Twelve drummers drumming"
  );
begin
  for day in first..twelfth loop
      put( "On the " ) @ ( day ) @ ( " day of Christmas," );
      new_line;
      put_line( "My true love gave to me:" );
      for subday in reverse first..day loop
          put_line( gifts( subday ) );
      end loop;
      if day = first then
          gifts( day ) := strings.replace_slice( gifts( day ), 2, 2, "And a" );
      end if;
      new_line;
  end loop;
  command_line.set_exit_status( 0 );
end twelve_days;

SQL

Demonstration of Oracle 12c "with" clause enhancement.

with
function nl ( s in varchar2 )
return varchar2
is
begin
        return chr(10) || s;
end nl;
function v ( d number, x number, g in varchar2 )
return varchar2
is
begin
        return
        case when d >= x then nl (g) end;
end v;
select 'On the '
        || to_char(to_date(level,'j'),'jspth' )
        || ' day of Christmas,'
        || nl( 'my true love sent to me:')
        || v ( level, 12, 'Twelve drummers drumming,' )
        || v ( level, 11, 'Eleven pipers piping,' )
        || v ( level, 10, 'Ten lords a-leaping,' )
        || v ( level, 9, 'Nine ladies dancing,' )
        || v ( level, 8, 'Eight maids a-milking,' )
        || v ( level, 7, 'Seven swans a-swimming,' )
        || v ( level, 6, 'Six geese a-laying,' )
        || v ( level, 5, 'Five golden rings!' )
        || v ( level, 4, 'Four calling birds,' )
        || v ( level, 3, 'Three French hens,' )
        || v ( level, 2, 'Two turtle doves,' )
        || v ( level, 1, case level when 1 then 'A' else 'And a' end || ' partridge in a pear tree.' )
        || nl(null)
        "The Twelve Days of Christmas"
from dual
connect by level <= 12
/

output:

The Twelve Days of Christmas
--------------------------------------------------------------------------------
On the first day of Christmas,
my true love sent to me:
A partridge in a pear tree.

...

On the twelfth day of Christmas,
my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings!
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.

Swift

Works with: Swift version 2.1
let gifts = [ "partridge in a pear tree", "Two turtle doves", 
              "Three French hens",        "Four calling birds",       
              "Five gold rings",          "Six geese a-laying", 
              "Seven swans a-swimming",   "Eight maids a-milking",
              "Nine ladies dancing",      "Ten lords a-leaping", 
              "Eleven pipers piping",     "Twelve drummers drumming" ]

let nth = [ "first",   "second", "third", "fourth", "fifth",    "sixth",
            "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]

func giftsForDay(day: Int) -> String {
  var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n"
  if day > 1 {
    for again in 1...day-1 {
      let n = day - again 
      result += gifts[n]
      if n > 1 { result += "," }
      result += "\n"
    }
    result += "And a "
  } else {
    result += "A "
  }
  return result + gifts[0] + ".\n";
}

for day in 1...12 {
  print(giftsForDay(day))
}
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

Tailspin

def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
  'a partridge in a pear tree',
  'two turtle-doves',
  'three French hens',
  'four calling birds',
  'five golden rings',
  'six geese a-laying',
  'seven swans a-swimming',
  'eight maids a-milking',
  'nine ladies dancing',
  'ten lords a-leaping',
  'eleven pipers piping',
  'twelve drummers drumming'
];
templates punctuation
  <=1> '.' !
  <=2> ' and' !
  <=5> ';' !
  <> ',' !
end punctuation

1..12 -> \singVerse(
  'On the $ordinal($); day of Christmas,
my true love gave to me:
' !
  $..1:-1 -> '$gift($);$->punctuation;
' !
'
' !
\singVerse) -> !OUT::write
Output:
On the first day of Christmas,
my true love gave to me:
a partridge in a pear tree.

On the second day of Christmas,
my true love gave to me:
two turtle-doves and
a partridge in a pear tree.

...

On the twelfth day of Christmas,
my true love gave to me:
twelve drummers drumming,
eleven pipers piping,
ten lords a-leaping,
nine ladies dancing,
eight maids a-milking,
seven swans a-swimming,
six geese a-laying,
five golden rings;
four calling birds,
three French hens,
two turtle-doves and
a partridge in a pear tree.


Terraform

locals {
  days = [ "first",   "second", "third", "fourth", "fifth",    "sixth",
           "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]
  gifts = [
    "A partridge in a pear tree.",
    "Two turtle doves, and",
    "Three French hens,",
    "Four calling birds,",
    "Five gold rings,",
    "Six geese a-laying,",
    "Seven swans a-swimming,",
    "Eight maids a-milking,",
    "Nine ladies dancing,",
    "Ten lords a-leaping,",
    "Eleven pipers piping,",
    "Twelve drummers drumming,"
  ]
}

data "template_file" "days" {
  count = 12
  template = "On the ${local.days[count.index]} day of Christmas, my true love sent to me:\n${join("\n",[for g in range(count.index,-1,-1): local.gifts[g]])}"
}

output "lyrics" {
  value = join("\n\n",[for t in data.template_file.days: t.rendered])
}


Output:
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

lyrics = <<EOT
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.
EOT

Tcl

Works with: Tcl version 8.6
set days {
    first second third fourth fifth sixth
    seventh eighth ninth tenth eleventh twelfth
}
set gifts [lreverse {
    "A partridge in a pear tree."
    "Two turtle doves, and"
    "Three french hens,"
    "Four calling birds,"
    "Five golden rings,"
    "Six geese a-laying,"
    "Seven swans a-swimming,"
    "Eight maids a-milking,"
    "Nine ladies dancing,"
    "Ten lords a-leaping,"
    "Eleven pipers piping,"
    "Twelve drummers drumming,"
}]

set n -1;puts [join [lmap day $days {
    format "On the $day day of Christmas,\nMy true love gave to me:\n%s" \
	    [join [lrange $gifts end-[incr n] end] \n]
}] \n\n]
Output:
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves, and
A partridge in a pear tree.

On the third day of Christmas,
My true love gave to me:
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the fourth day of Christmas,
My true love gave to me:
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the fifth day of Christmas,
My true love gave to me:
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the sixth day of Christmas,
My true love gave to me:
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the seventh day of Christmas,
My true love gave to me:
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the eighth day of Christmas,
My true love gave to me:
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the ninth day of Christmas,
My true love gave to me:
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the tenth day of Christmas,
My true love gave to me:
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the eleventh day of Christmas,
My true love gave to me:
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

uBasic/4tH

Dim @n(12) : Dim @v(12)                ' define both arrays

Proc _DataDays                         ' put data on the stack

For i=11 To 0 Step -1                  ' read them in
  @n(i) = Pop()
Next

Proc _DataGifts                        ' put data on the stack

For i=11 To 0 Step -1                  ' read them in
  @v(i) = Pop()
Next

For i=0 To 11                          ' print all twelve verses
  Print "On the ";Show(@n(i));" day of Christmas"
  Print "My true love gave to me:"

  For j=i To 0 Step -1                 ' show list of gifts
    Print Show(@v(j))
  Next

  Print                                ' next verse
Next
End

_DataDays
  Push "first", "second", "third",    "fourth"
  Push "fifth", "sixth",  "seventh",  "eighth"
  Push "ninth", "tenth",  "eleventh", "twelfth"
Return

_DataGifts
  Push "A partridge in a pear tree."
  Push "Two turtle doves and"
  Push "Three french hens"
  Push "Four calling birds"
  Push "Five golden rings"
  Push "Six geese a-laying"
  Push "Seven swans a-swimming"
  Push "Eight maids a-milking"
  Push "Nine ladies dancing"
  Push "Ten lords a-leaping"
  Push "Eleven pipers piping"
  Push "Twelve drummers drumming"
Return

UNIX Shell

Works with: Bourne Again SHell
Works with: Korn Shell version 93
#!/usr/bin/env bash
ordinals=(first   second third fourth fifth    sixth
          seventh eighth ninth tenth  eleventh twelfth)

gifts=( "A partridge in a pear tree." "Two turtle doves and"
        "Three French hens,"          "Four calling birds,"
        "Five gold rings,"            "Six geese a-laying,"
        "Seven swans a-swimming,"     "Eight maids a-milking,"
        "Nine ladies dancing,"        "Ten lords a-leaping,"
        "Eleven pipers piping,"       "Twelve drummers drumming," )

echo_gifts() {
  local i day=$1
  echo "On the ${ordinals[day]} day of Christmas, my true love sent to me:"
  for (( i=day; i >=0; --i )); do
    echo "${gifts[i]}"
  done
  echo
}

for (( day=0; day < 12; ++day )); do
  echo_gifts $day
done

The above will also work in zsh if the index range is changed from 0..11 to 1..12.

Works with: Bourne Shell

(requires the seq command)

#!/bin/sh
ordinal() {
  n=$1
  set first   second third fourth fifth    sixth \
      seventh eighth ninth tenth  eleventh twelfth
  shift $n
  echo $1
}

gift() {
  n=$1
  set "A partridge in a pear tree." "Two turtle doves and"      \
      "Three French hens,"          "Four calling birds,"       \
      "Five gold rings,"            "Six geese a-laying,"       \
      "Seven swans a-swimming,"     "Eight maids a-milking,"    \
      "Nine ladies dancing,"        "Ten lords a-leaping,"      \
      "Eleven pipers piping,"       "Twelve drummers drumming," 
  shift $n
  echo "$1"
}

echo_gifts() {
  day=$1
  echo "On the `ordinal $day` day of Christmas, my true love sent to me:"
  for i in `seq $day 0`; do
    gift $i
  done
  echo
}

for day in `seq 0 11`; do
  echo_gifts $day
done
Output:
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.

VBA

Sub Main()
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim s, n
   s = Split(SING_, "$")
   n = Split(NUMBERS_, " ")
   ReDim strReturn(UBound(s))
   For i = LBound(s) To UBound(s)
      strReturn(i) = Replace(BASE_, "(X)", n(i))
      For j = c To 0 Step -1
         strReturn(i) = strReturn(i) & s(j) & vbCrLf
      Next
      c = c + 1
   Next i
   strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
   Debug.Print Join(strReturn, vbCrLf)
End Sub
Output:
On the first day of Christmas,
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas,
My true love gave to me:
Two turtle doves and
A partridge in a pear tree.

On the third day of Christmas,
My true love gave to me:
Three french hens
Two turtle doves and
A partridge in a pear tree.
[...]
On the twelfth day of Christmas,
My true love gave to me:
Twelve drummers drumming
Eleven pipers piping
Ten lords a-leaping
Nine ladies dancing
Eight maids a-milking
Seven swans a-swimming
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves 
And a partridge in a pear tree.

VBScript

days = Array("first","second","third","fourth","fifth","sixth",_
		"seventh","eight","ninth","tenth","eleventh","twelfth")
		
gifts = Array("A partridge in a pear tree","Two turtle doves","Three french hens",_
	"Four calling birds","Five golden rings","Six geese a-laying","Seven swans a-swimming",_
	"Eight maids a-milking","Nine ladies dancing","Ten lords a-leaping","Eleven pipers piping",_
	"Twelve drummers drumming")
	
For i = 0 To 11
	WScript.StdOut.Write "On the " & days(i) & " day of Christmas"
	WScript.StdOut.WriteLine
	WScript.StdOut.Write "My true love sent to me:"
	WScript.StdOut.WriteLine
	If i = 0 Then
		WScript.StdOut.Write gifts(i)
	Else
		For j = i To 0 Step - 1
			If j = 0 Then 
				WScript.StdOut.Write "and " & gifts(0)
			Else
				WScript.StdOut.Write gifts(j)
				WScript.StdOut.WriteLine
			End If
		Next
	End If
		WScript.StdOut.WriteBlankLines(2)
Next


Vedit macro language

This example uses calculated call targets. Note that in the gift subroutines, the execution falls through all the following subroutines and returns only after the gift 1 routine.

for (#1 = 1; #1 <= 12; #1++) {
    Num_Str(#1, 9, LEFT)
    IT("On the ")
    Call("day |@(9)")
    IT(" day of Christmas, my true love sent to me:") IN
    Call("gift |@(9)")
    IN
}
return

:day 1:  IT("first")    return
:day 2:  IT("second")   return
:day 3:  IT("third")    return
:day 4:  IT("fourth")   return
:day 5:  IT("fifth")    return
:day 6:  IT("sixth")    return
:day 7:  IT("seventh")  return
:day 8:  IT("eighth")   return
:day 9:  IT("ninth")    return
:day 10: IT("tenth")    return
:day 11: IT("eleventh") return
:day 12: IT("twelfth")  return

:gift 12: IT("Twelve drummers drumming,") IN
:gift 11: IT("Eleven pipers piping,") IN
:gift 10: IT("Ten lords a-leaping,") IN
:gift 9:  IT("Nine ladies dancing,") IN
:gift 8:  IT("Eight maids a-milking,") IN
:gift 7:  IT("Seven swans a-swimming,") IN
:gift 6:  IT("Six geese a-laying,") IN
:gift 5:  IT("Five gold rings,") IN
:gift 4:  IT("Four calling birds,") IN
:gift 3:  IT("Three French hens,") IN
:gift 2:  IT("Two turtle doves, and") IN
:gift 1:  IT("A partridge in a pear tree.") IN
return

Vim Script

Translation of: Raku
let b:days=["first",   "second", "third", "fourth", "fifth",    "sixth", 
  \         "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth"]

let b:gifts=[
  \ "And a partridge in a pear tree.",
  \ "Two turtle doves,",
  \ "Three french hens,",
  \ "Four calling birds,",
  \ "Five golden rings,",
  \ "Six geese a-laying,",
  \ "Seven swans a-swimming,",
  \ "Eight maids a-milking,",
  \ "Nine ladies dancing,",
  \ "Ten lords a-leaping,",
  \ "Eleven pipers piping,",
  \ "Twelve drummers drumming,"
\ ]

function Nth(n)
  echom "On the " . b:days[a:n] . " day of Christmas, my true love gave to me:"
endfunction

call Nth(0)
echom toupper(strpart(b:gifts[0], 4, 1)) . strpart(b:gifts[0], 5)

let b:day = 1
while (b:day < 12) 
  echom " "
  call Nth(b:day)
  let b:gift = b:day
  while (b:gift >= 0)
    echom b:gifts[b:gift]
    let b:gift = b:gift - 1
  endwhile
  let b:day = b:day + 1
endwhile
Output:
On the first day of Christmas, my true love gave to me:
A partridge in a pear tree.

On the second day of Christmas, my true love gave to me:
Two turtle doves,
And a partridge in a pear tree.

[...]

On the twelfth day of Christmas, my true love gave to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

Visual Basic .NET

Translation of: C#

Compiler: Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)

Module Program
    Sub Main()
        Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
        Dim gifts = New String(11) {
            "A partridge in a pear tree",
            "Two turtle doves",
            "Three french hens",
            "Four calling birds",
            "Five golden rings",
            "Six geese a-laying",
            "Seven swans a-swimming",
            "Eight maids a-milking",
            "Nine ladies dancing",
            "Ten lords a-leaping",
            "Eleven pipers piping",
            "Twelve drummers drumming"
        }

        For i = 0 To 11
            Console.WriteLine($"On the {days(i)} day of Christmas, my true love gave to me")

            For j = i To 0 Step -1
                Console.WriteLine(gifts(j))
            Next

            Console.WriteLine()

            If i = 0 Then gifts(0) = "And a partridge in a pear tree"
        Next
    End Sub
End Module

Wren

var days = [
    "first", "second", "third", "fourth", "fifth", "sixth",
    "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
]

var gifts = [
    "A partridge in a pear tree.", "Two turtle doves and", "Three french hens",
    "Four calling birds", "Five golden rings", "Six geese a-laying",
    "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing",
    "Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming"
]

for (i in 0..11) {
    System.print("On the %(days[i]) day of Christmas,")
    System.print("My true love gave to me:")
    for (j in i..0) System.print(gifts[j])
    System.print()
}

XPL0

int     Day, Gift, D, G;
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
        "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Gift:= [0,
        "A partridge in a pear tree.",
        "Two turtle doves, and",
        "Three french hens,",
        "Four calling birds,",
        "Five golden rings,",
        "Six geese a-laying,",
        "Seven swans a-swimming,",
        "Eight maids a-milking,",
        "Nine ladies dancing,",
        "Ten lords a-leaping,",
        "Eleven pipers piping,",
        "Twelve drummers drumming,"];
for D:= 1 to 12 do
        [Text(0, "On the ");  Text(0, Day(D));
         Text(0, " day of Christmas
My true love gave to me:
");     for G:= D downto 1 do
                [Text(0, Gift(G));  CrLf(0)];
        CrLf(0);
        ];
]
Output:
On the first day of Christmas
My true love gave to me:
A partridge in a pear tree.

On the second day of Christmas
My true love gave to me:
Two turtle doves, and
A partridge in a pear tree.
. . .
On the twelfth day of Christmas
My true love gave to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

Z80 Assembly

You can copy-paste this into the WinAPE assembler and it will work. Run it with CALL &8000 (remember that Shift+6 on the keyboard will give you & on Winape!) Press any key to advance to the next verse. This was repurposed from my entry to the Old Lady Swallowed A Fly task.


waitChar equ &BB06   ;wait for a key press
PrintChar equ &BB5A   ;print accumulator to screen

org &8000

	ld ix,VerseTable
	inc ix
	inc ix
	ld iy,SongLookup
	
	ld b,12          ;12 verses total
outerloop_song:
	push af          ;new line
		ld a,13
		call PrintChar
		ld a,10
		call PrintChar
	pop af
	push bc
		push ix
			ld ix,VerseTable
			ld a,(ix+0)
			ld c,a        ;get the low byte of verse ptr
			ld a,(ix+1)
			ld b,a        ;get the high byte
		pop ix
		;bc = the memory location of Verse1
		call loop_meta_PrintString
		push ix
		push iy
			
			ld iy,Verse0
			inc (IY+1)
			inc (IY+1)
			
			ld a,(IX+2)
			ld (IY+7),a
			ld a,(IX+3)
			ld (IY+8),a
		pop iy
		pop ix
		inc ix
		inc ix
	pop bc


	call WaitChar   ;wait for user to press any key before 
	;continuing so they have time to read it.


	djnz outerloop_song

ReturnToBasic:
		ret		
		
loop_meta_PrintString:
		ld a,(bc)
		or a		;compare A to 0. 0 is the null terminator for verses.
		ret z
		cp 255		;255 means "goto the verse specified after the 255"
		jr z,GotoPreviousVerse
		ld (smc_loop_meta_PrintString_alpha+2),a
		;use self modifying code to point IY's offset to the correct 
		;	song line, without changing IY itself.
		inc a
		ld (smc_loop_meta_PrintString_beta+2),a
smc_loop_meta_PrintString_alpha:
		ld a,(iy+0)	;the "+0" gets clobbered with the desired lyric low byte
		ld L,a
smc_loop_meta_PrintString_beta:
		ld a,(iy+0)	;the "+0" gets clobbered with the desired lyric high byte
		ld H,a
		call PrintString	;now print the string in HL.
		inc bc
		jp loop_meta_PrintString
	
GotoPreviousVerse:
	inc bc		;advance past &FF opcode
	ld a,(bc)   ;get low byte
	ld e,a
	inc bc		;advance to high byte
	ld a,(bc)
	ld d,a
	push de
	pop bc
	jp loop_meta_PrintString
	
	
PrintString:
	ld a,(hl)
	or a
	ret z
	call PrintChar
	inc hl
	jr PrintString

;;;; data
VerseTable:
	word Verse0
	word Verse1
	word Verse2
	word Verse3
	word Verse4
	word Verse5
	word Verse6
	word Verse7
	word Verse8
	word Verse9
	word Verse10
	word Verse11
	word Verse12
	
Verse0:
	byte 2
	byte 32			;increment this by 2 after each verse.
	byte 4,56,6,56
	byte 255
	word Verse1		;look up next verse and write that here too.
					;repeat until a hardcoded 12 verses are "sung"
	
Verse1:
	byte 8,56,0
Verse2:
	byte 10,56,255
	word Verse1
Verse3:
	byte 12,56,255
	word Verse2
Verse4:
	byte 14,56,255
	word Verse3
Verse5:
	byte 16,56,255
	word Verse4
Verse6:
	byte 18,56,255
	word Verse5
Verse7:
	byte 20,56,255
	word Verse6
Verse8:
	byte 22,56,255
	word Verse7
Verse9:
	byte 24,56,255
	word Verse8
Verse10:
	byte 26,56,255
	word Verse9
Verse11:
	byte 28,56,255
	word Verse10
Verse12:
	byte 30,56,255
	word Verse11

	 

SongLookup:
		word null		;0
		word Day_Part1	;2
		word Day_Part2	;4
		word Day_Part3	;6
		word Day1		;8
		
		word Day2		;10
		word Day3		;12
		word Day4		;14
		word Day5		;16
		word Day6		;18
		
		word Day7		;20
		word Day8		;22
		word Day9		;24
		word Day10		;26
		word Day11		;28
		
		word Day12		;30
		word First		;32
		word Second		;34
		word Third		;36
		word Fourth		;38
		
		word Fifth		;40
		word Sixth		;42
		word Seventh	;44
		word Eighth		;46
		word Ninth		;48
		word Tenth		;50
		
		word Eleventh	;52
		word Twelfth	;54
		
		word Song_NewLine	;56
		
null:
		byte 0
Day_Part1:
		byte "On the",0
Day_Part2:
		byte "day of Christmas,",0
Day_Part3:
		byte "my true love gave to me",0
Day1:
		byte "a partridge in a pear tree.",0
Day2:
		byte "two turtle doves, and",0
Day3:
		byte "three french hens",0
Day4:
		byte "four calling birds",0
Day5:
		byte "five golden rings",0
Day6:
		byte "six geese a-laying",0
Day7:
		byte "seven swans a-swimming",0
Day8:
		byte "eight maids a-milking",0
Day9:
		byte "nine ladies dancing",0
Day10:
		byte "ten lords a-leaping",0
Day11:
		byte "eleven pipers piping",0
Day12:
		byte "twelve drummers drumming",0
First:
		byte " first ",0
Second:
		byte " second ",0
Third:
		byte " third ",0
Fourth:
		byte " fourth ",0
Fifth:
		byte " fifth ",0
Sixth:
		byte " sixth ",0
Seventh:
		byte " seventh ",0
Eighth:
		byte " eighth ",0
Ninth:
		byte " ninth ",0
Tenth:
		byte " tenth ",0
Eleventh:
		byte " eleventh ",0
Twelfth:
		byte " twelfth ",0

Song_NewLine:
		byte 13,10,0		;control codes for a new line.

zkl

Translation of: Python
gifts:=
#<<<
"A beer, in a tree.; Two turtlenecks; Three french toast;
Four pounds of backbacon; Five golden touques; Six packs of two-four; 
Seven packs of smokes; Eight comic books; Nine back up singers;
Ten feet of snow; Eleven hosers hosing; Twelve dozen donuts"
#<<<
.split(";").apply("strip");

days:=("first second third fourth fifth sixth seventh eighth ninth tenth "
      "eleventh twelfth").split();
 
foreach n,day in (days.enumerate()){ n+=1;
   g:=gifts[0,n].reverse();
   println("On the %s day of Christmas\nMy true love gave to me:\n".fmt(day),
         g[0,-1].concat("\n"), (n>1) and " and\n" or "", g[-1], "\n");
}
Output:
On the first day of Christmas
My true love gave to me:
A beer, in a tree.

On the second day of Christmas
My true love gave to me:
Two turtlenecks and
A beer, in a tree.

On the third day of Christmas
My true love gave to me:
Three french toast
Two turtlenecks and
A beer, in a tree.

On the fourth day of Christmas
My true love gave to me:
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the fifth day of Christmas
My true love gave to me:
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the sixth day of Christmas
My true love gave to me:
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the seventh day of Christmas
My true love gave to me:
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the eighth day of Christmas
My true love gave to me:
Eight comic books
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the ninth day of Christmas
My true love gave to me:
Nine back up singers
Eight comic books
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the tenth day of Christmas
My true love gave to me:
Ten feet of snow
Nine back up singers
Eight comic books
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the eleventh day of Christmas
My true love gave to me:
Eleven hosers hosing
Ten feet of snow
Nine back up singers
Eight comic books
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.

On the twelfth day of Christmas
My true love gave to me:
Twelve dozen donuts
Eleven hosers hosing
Ten feet of snow
Nine back up singers
Eight comic books
Seven packs of smokes
Six packs of two-four
Five golden touques
Four pounds of backbacon
Three french toast
Two turtlenecks and
A beer, in a tree.