Created
April 11, 2021 13:30
-
-
Save hugoduncan/5fb1afd91e9da89a19a2987a52150c23 to your computer and use it in GitHub Desktop.
Predicate for testing whether a value is primitive in clojure
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
(definterface IPrimitive | |
(is_primitive [^boolean x]) | |
(is_primitive [^float x]) | |
(is_primitive [^double x]) | |
(is_primitive [^int x]) | |
(is_primitive [^long x]) | |
(is_primitive [^Object x])) | |
(deftype IsPrimitive [] | |
IPrimitive | |
(is_primitive [_ ^float x] true) | |
(is_primitive [_ ^double x] true) | |
(is_primitive [_ ^int x] true) | |
(is_primitive [_ ^long x] true) | |
(is_primitive [_ ^boolean x] true) | |
(is_primitive [_ ^Object x] false)) | |
(def ^IsPrimitive is-primitive (IsPrimitive.)) | |
(defmacro primitive? | |
"Predicate for x being of primitive type." | |
[x] | |
`(.is_primitive is-primitive ~x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment