Simple branching if-else logic in Clojure

I hit my head against the wall for the past 30 minutes, trying to figure out why this simple code is not working. All he does is check to see if at least one command line argument is specified.

(defn check_args [] (if (first *command-line-args*) println "value is not nil" println "value is nil")) (check_args) 

When I run the code, I get a runtime exception that states:

 java.lang.RuntimeException: Too many arguments to if 

I am sure this is something simple, but for my life I can’t understand where the problem is. The code pulling the first element from the sequence returns the first element in the sequence, or nil if it does not exist, so it seems pretty simple.

+4
source share
1 answer

You lose parentheses - a common mistake.

try it

 (defn check_args [] (if (first *command-line-args*) (println "value is not nil") (println "value is nil"))) 
+8
source

Source: https://habr.com/ru/post/1446239/


All Articles