In Common Lisp you use the (null x) function to check for empty lists and nil values.
Most logically this maps to
(or (nil? x) (= '() x))
In clojure. Can someone suggest a more idiomatic way to do it in Clojure?
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.
To get the same result for an empty list in Clojure as you do in Common Lisp, use the
empty?function. This function is in the core library: no imports are necessary.It is also a predicate, and suffixed with a
?, making it a little clearer what exactly you’re doing in the code.As j-g faustus already noted,
seqcan be used for a similar effect.