you wrap a call to Thread/sleep in parens, in clojure this means you want to call it, Thread/sleep returns nil and calling nil gives a NullpointerException
Parens are not for grouping or sequencing things in clojure, and you don't need them here - fn has an implicit do block already, in other contexts where there isn't a do block implicitly, you can use do to sequence expressions On Tue, Oct 24, 2017 at 5:26 PM yihao yang <yangyihao1...@gmail.com> wrote: > Hi, all > > I want to do sth. like query until timeout. So I write a function below. > (defn wait-ls-ready > [] > (let [pair-fn (fn [] ( > (Thread/sleep 1000) > (let [ret (try > (c/exec :ls) > 0 > (catch RuntimeException e -1) > ), > time-now (quot (System/currentTimeMillis) > 1000)] > '(ret (- time-now start-time)) > ) > ))] > (loop [start-time (quot (System/currentTimeMillis) 1000) > time-out 10] > (let [[ret time-delta] (pair-fn)] > (info node "Waiting gsql works...") > (if (= 0 ret) 0 > (if (> time-delta time-out) > (throw (RuntimeException. > (str "'ls' not working in " time-out "seconds."))) > (recur start-time time-out)))) > ) > ) > ) > > But it returns a NullpointerException after 1 seconds. Could anyone help > me out? > > Thanks, > Yihao > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.