The Twelve Days of Christmas: Difference between revisions

(+add Pike)
Line 3,902:
A partridge in a pear tree
</pre>
 
=={{header|Picat}}==
<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.</lang>
 
 
DCG version:
<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".</lang>
 
 
=={{header|PicoLisp}}==
495

edits