Is it possible to detect in some way whether a Clojure expression is guaranteed to be primitive?
e.g. I’d like a macro that could do this
(is-primitive-expression? (+ 1.0 2.0))
=> true
(is-primitive-expression? (+ 1N 2.0))
=> false
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure I quite understand what a primitive expression is (still reading up on it). However, I found a function from
clojure.contrib.repl-utilscalledexpression-info, that claims to return information about whether the expression is primitive or not.See here: http://clojuredocs.org/clojure_contrib/clojure.contrib.repl-utils/expression-info
I simply copied the source code and tried it out, but discovered I needed to do this import first:
However, I tried it out with your examples, but it returned true for both (I tried quoted and unquoted expressions because I could not tell which one it required):
Maybe some of this could provide you with useful clues/hints, but this may be very unhelpful seeing as I don’t really understand what you are asking (yet).