Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple if-else branching logic in Clojure

Tags:

clojure

I've been banging my head against the wall for the past 30 minutes trying to figure out why this simple code doesn't work. All it does is check to see if at least one command line argument has been 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 end up with a runtime exception that says:

java.lang.RuntimeException: Too many arguments to if

I'm sure it's something simple, but for the life of me I can't figure out where the problem is. The code pulling the first item off of the sequence returns the first item in the sequence, or nil if it doesn't exist, so it seems pretty straight-forward.

like image 833
Jack Slingerland Avatar asked Feb 18 '23 12:02

Jack Slingerland


1 Answers

You lose parentheses - common mistake.

Try this

(defn check_args []
    (if (first *command-line-args*)
        (println "value is not nil")
        (println "value is nil")))
like image 179
mishadoff Avatar answered Feb 28 '23 08:02

mishadoff