1

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

2 Answers 2

5

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"))))
Sign up to request clarification or add additional context in comments.

Comments

4

In Clojure ))))))) is totally normal and you see it everywhere, no cause for concern.

On the other hand (( should stand out and catch your eye. It very often means:

  • someone is returning a function.
  • that function should be immediately run.

This pattern is not wrong in any way, just learning to spot it is a useful way to get used to reading Clojure code quickly. In this case it likely means there are too many opening (s in

((db/addUser email phone roleId status) (str "true"))))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.