Last active
February 24, 2018 03:16
-
-
Save mfikes/3ed89b767048e109891464f1f7e7151b to your computer and use it in GitHub Desktop.
clojure / cljs spec macro
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
(ns foo.core) | |
(defmacro my-def | |
[x] | |
`(clojure.spec.alpha/def ~x int?)) |
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
user=> (require '[clojure.spec.alpha :as s]) | |
nil | |
user=> (require 'foo.core) | |
nil | |
user=> (foo.core/my-def ::a) | |
:user/a | |
user=> (s/valid? ::a 3) | |
true | |
user=> (macroexpand '(foo.core/my-def ::a)) | |
(clojure.spec.alpha/def-impl (quote :user/a) (quote clojure.core/int?) clojure.core/int?) | |
user=> ::s/invalid | |
:clojure.spec.alpha/invalid |
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
cljs.user=> (require '[clojure.spec.alpha :as s]) | |
cljs.user=> (require-macros 'foo.core) | |
cljs.user=> (foo.core/my-def ::a) | |
:cljs.user/a | |
cljs.user=> (s/valid? ::a 3) | |
true | |
cljs.user=> (macroexpand '(foo.core/my-def ::a)) | |
(cljs.spec.alpha/def-impl (quote :cljs.user/a) (quote cljs.core/int?) clojure.core/int?) | |
cljs.user=> ::s/invalid | |
:cljs.spec.alpha/invalid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment