Reputation: 690
I want to code a simple derivative solver. Therefore I need some code that is capable of checking which operator is used, but I just can't get it to work. I'm a newbie in clojure so I might overlook some important basic thing here .. :)
This is some test code:
(defn get-input []
'(* x y))
(println (get-input))
(println (first (get-input)))
(println
(if (= * (first (get-input)))
"Y"
"N"))
This yields the following output:
(* x y)
*
N
As you can see, the first element of the input list is an asterisk, but the if special form yields false (and therefore "N" is printed). How can I modify the if to check if that first element of the list is indeed an asterisk?
Upvotes: 0
Views: 50
Reputation: 92117
The first item of that list is not the function referred to by *
, but the symbol named *
, which you can get by quoting it:
(if (= '* (first (get-input)))
...)
Upvotes: 1