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>(define take (lambda (n lst)
<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) (cdr lst))))))
(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
(day 1 (1+ day)))
; are divided between (add1) and (1+).
(day 1 (+ 1 day)))
((null? left) #t)
((null? left) #t)


Line 4,876: Line 4,879:
(newline)
(newline)


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