Created
January 23, 2013 19:01
-
-
Save bowbow99/4611628 to your computer and use it in GitHub Desktop.
Common Lisp の type system で fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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