The Twelve Days of Christmas: Difference between revisions
Content added Content deleted
(→{{header|Scheme}}: Now works in Chez, Guile, MIT Scheme, and Racket.) |
|||
Line 4,851: | Line 4,851: | ||
=={{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. |
||
<lang scheme> |
<lang scheme>; Racket has this built in, but it's not part of R5RS |
||
(define (take lst n) |
|||
(if (or (null? lst) (<= n 0)) |
(if (or (null? lst) (<= n 0)) |
||
'() |
'() |
||
(cons (car lst) (take (- n 1 |
(cons (car lst) (take (cdr lst) (- n 1))))) |
||
(let |
(let |
||
Line 4,868: | Line 4,869: | ||
(do ((left days (cdr left)) |
(do ((left days (cdr left)) |
||
; No universal predefined (+ 1) function, sadly. Implementations |
|||
⚫ | |||
; are divided between (add1) and (1+). |
|||
⚫ | |||
((null? left) #t) |
((null? left) #t) |
||
Line 4,876: | Line 4,879: | ||
(newline) |
(newline) |
||
(do ((daily (reverse (take |
(do ((daily (reverse (take gifts day)) (cdr daily))) |
||
((null? daily) #t) |
((null? daily) #t) |
||