mardi 27 décembre 2016

Clojure: Compare an operator to list element (data)

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?

Aucun commentaire:

Enregistrer un commentaire