The Twelve Days of Christmas: Difference between revisions

m
→‎{{header|Scheme}}: Reformat; removed square brackets which are not part of standard Scheme
(→‎{{header|Scheme}}: Add implementation)
m (→‎{{header|Scheme}}: Reformat; removed square brackets which are not part of standard Scheme)
Line 4,851:
=={{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"))
"eighth" "ninth" "tenth" "eleventh" "twelfth"))
 
(gifts '("A partridge in a pear tree." "Two turtle doves, and"
"Three French hens," "Four calling birds,"
Line 4,863 ⟶ 4,865:
"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))
(do (day(left 1days (+ daycdr 1)left))
(day 1 ((null?+ left)day #t1)))
(display "On(null? theleft) "#t)
 
(display (car left))
(display "On day of Christmas, my true love sent tothe me:")
(display (car (newlineleft))
(display " day of Christmas, my true love sent to me:")
(do ((daily (reverse (take day gifts)) (cdr daily)))
((null? daily) #tnewline)
 
(display (car daily))
(do ((daily (reverse (take day gifts)) (newlinecdr daily)))
(newline)(null? daily) #t)
 
(display (car leftdaily))
(newline))
(newline)))
 
(exit)</lang>
 
1,480

edits