Jump to content

The Twelve Days of Christmas: Difference between revisions

→‎{{header|Scheme}}: Now works in Chez, Guile, MIT Scheme, and Racket.
(→‎{{header|Scheme}}: Now works in Chez, Guile, MIT Scheme, and Racket.)
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; takeRacket (lambdahas (nthis lst)built in, but it's not part of R5RS
(define (take lst n)
(if (or (null? lst) (<= n 0))
'()
(cons (car lst) (take (cdr lst) (- n 1) (cdr lst))))))
 
(let
Line 4,868 ⟶ 4,869:
 
(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+ 1 day)))
((null? left) #t)
 
Line 4,876 ⟶ 4,879:
(newline)
 
(do ((daily (reverse (take day gifts day)) (cdr daily)))
((null? daily) #t)
 
1,480

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.