The Twelve Days of Christmas: Difference between revisions
Content added Content deleted
(→{{header|Common Lisp}}: Simplify) |
(→{{header|Scheme}}: Add implementation) |
||
Line 4,847: | Line 4,847: | ||
Three French hens, |
Three French hens, |
||
Two turtle doves and |
Two turtle doves and |
||
A partridge in a pear tree.</pre> |
|||
=={{header|Scheme}}== |
|||
Without Common Lisp's <tt>format</tt>, we sadly have to hard-code the list of ordinals. |
|||
<lang scheme>(define take (lambda [n lst] ; return the first n items of a list |
|||
(if (or (null? lst) (<= n 0)) |
|||
'() |
|||
(cons (car lst) (take (- n 1) (cdr lst)))))) |
|||
(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)) |
|||
(day 1 (+ day 1))) |
|||
((null? left) #t) |
|||
(display "On the ") |
|||
(display (car left)) |
|||
(display " day of Christmas, my true love sent to me:") |
|||
(newline) |
|||
(do ((daily (reverse (take day gifts)) (cdr daily))) |
|||
((null? daily) #t) |
|||
(display (car daily)) |
|||
(newline)) |
|||
(newline))) |
|||
(exit)</lang> |
|||
{{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> |
A partridge in a pear tree.</pre> |
||