Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created January 23, 2013 19:01
Show Gist options
  • Save bowbow99/4611628 to your computer and use it in GitHub Desktop.
Save bowbow99/4611628 to your computer and use it in GitHub Desktop.
Common Lisp の type system で fizzbuzz
(defun fizzp (n) (zerop (mod n 3)))
(defun buzzp (n) (zerop (mod n 5)))
(deftype fizz () `(and integer (satisfies fizzp)))
(deftype buzz () `(and integer (satisfies buzzp)))
(deftype fizzbuzz () `(and fizz buzz))
(defun fizzbuzz-1 (n)
(etypecase n
(fizzbuzz (print "Fizz Buzz"))
(fizz (print "Fizz"))
(buzz (print "Buzz"))
(integer (print n))))
(defun fizzbuzz (start end)
(loop for n from start to end
do (fizzbuzz-1 n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment