Search code examples
clojureclojurescriptcompojureclojure-java-interop

java.lang.String cannot be cast to clojure.lang.IFn


I am trying to add some data into app engine datastore. This is my function

(defn createUser [email phone roleId status]
  (println (db/isIdExist "users" "email" email))
  (if (db/isIdExist "users" "email" email) 
    (str "false")
    ((db/addUser email phone roleId status) (str "true"))))

Here I want to print false in body according to the value of isIdExist function (which returns true if email already exists else false) now when I run this, If isIdExist == true then it prints false but when isIdExist == false it adds the value in datastore but gives this error. Can someone please help why it is happening and what concept of clojure am I missing here? Thanks


Solution

  • I assume db/addUser returns a string in which case you're trying to invoke the return value as a function. It looks like you want to perform the insert then return "true" so you can use do to sequence the two:

    (if (db/isIdExist "users" "email" email) 
      "false"
      (do
        (db/addUser email phone roleId status) 
        "true"))))