Skip to content

Instantly share code, notes, and snippets.

@yshl

yshl/fizzbuzz-1.scm

Last active Dec 19, 2015
Embed
What would you like to do?
FizzBuzz in Scheme
(define (fizzbuzz n c)
((lambda(d m g)
(g g 1
(lambda(l)
(m m l
(lambda(i c)
(d i 15
(lambda(b)
(if b
(c "FizzBuzz")
(d i 5
(lambda(b)
(if b
(c "Buzz")
(d i 3
(lambda(b)
(if b
(c "Fizz")
(c i)))))))))))
(lambda(l)
(m m l
(lambda(i c)
(c (print i)))
c))))))
(lambda(m n c)
(c (zero? (modulo m n))))
(lambda(m l f c)
(if (pair? l)
(f (car l)
(lambda(i)
(m m (cdr l) f
(lambda(l)
(c (cons i l))))))
(c '())))
(lambda(g i c)
(if (<= i n)
(g g (+ i 1)
(lambda(l)
(c (cons i l))))
(c '())))))
(call/cc
(lambda(c)
(fizzbuzz 100 c)))
(use srfi-1) ; for iota
(define (map-cpsfun fun lis)
(if (pair? lis)
(fun (car lis)
(lambda(elem)
(cons elem (map-cpsfun fun (cdr lis)))))
'()))
(define (fizzbuzz n)
(map-cpsfun
(lambda(i cont)
((lambda(printi)
(if (zero? (modulo i 5))
(cont (print "Buzz"))
(printi (lambda(cont2) (cont cont2)))))
(if (zero? (modulo i 3))
(begin (display "Fizz")
(lambda(c) (c (print ""))))
(lambda(c) (c (print i))))))
(iota n 1)))
(fizzbuzz 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment