Last active
November 9, 2017 15:02
-
-
Save missingfaktor/f26c810bf6f2469a6bc414c501329c8a to your computer and use it in GitHub Desktop.
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
akar.try-out=> (macroexpand-1 '(match n | |
(:and [(!div-by 3)][(!div-by 5)]) "Fizzbuzz" | |
[(!div-by 3)] "Fizz" | |
[(!div-by 5)] "Buzz" | |
:_ n)) | |
(akar.primitives/match* n | |
(akar.primitives/or-else | |
(akar.primitives/clause* (akar.combinators/!and (!div-by 3) (!div-by 5)) (clojure.core/fn [] "Fizzbuzz")) | |
(akar.primitives/clause* (!div-by 3) (clojure.core/fn [] "Fizz")) | |
(akar.primitives/clause* (!div-by 5) (clojure.core/fn [] "Buzz")) | |
(akar.primitives/clause* akar.patterns/!any (clojure.core/fn [] n)))) | |
akar.try-out=> (macroexpand-1 '(match [(mod n 3) (mod n 5)] | |
(:seq [0 0]) "Fizzbuzz" | |
(:seq [0 :_]) "Fizz" | |
(:seq [:_ 0]) "Buzz" | |
:_ n)) | |
(akar.primitives/match* [(mod n 3) (mod n 5)] | |
(akar.primitives/or-else | |
(akar.primitives/clause* (akar.combinators/!further-many akar.patterns/!seq [(akar.patterns/!constant 0) (akar.patterns/!constant 0)]) | |
(clojure.core/fn [] "Fizzbuzz")) | |
(akar.primitives/clause* (akar.combinators/!further-many akar.patterns/!seq [(akar.patterns/!constant 0) akar.patterns/!any]) | |
(clojure.core/fn [] "Fizz")) | |
(akar.primitives/clause* (akar.combinators/!further-many akar.patterns/!seq [akar.patterns/!any (akar.patterns/!constant 0)]) | |
(clojure.core/fn [] "Buzz")) | |
(akar.primitives/clause* akar.patterns/!any | |
(clojure.core/fn [] n)))) |
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
; Translating the original example directly | |
(doseq [n (range 1 101)] | |
(println (match [(mod n 3) (mod n 5)] | |
(:seq [0 0]) "Fizzbuzz" | |
(:seq [0 :_]) "Fizz" | |
(:seq [:_ 0]) "Buzz" | |
:_ n))) | |
; Using Akar's first class patterns | |
(defn !div-by [n] | |
(!pred (fn [m] (zero? (mod m n))))) | |
(doseq [n (range 1 101)] | |
(println (match n | |
(:and [(!div-by 3)][(!div-by 5)]) "Fizzbuzz" | |
[(!div-by 3)] "Fizz" | |
[(!div-by 5)] "Buzz" | |
:_ n))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is so nice. ;) Good job!