#clojure log - Oct 29 2015

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:08 Guest49090: how to change a variable value , defined by let

0:15 jeaye: Guest49090: Do so in a loop or recurse or, if you absolutely must, use an atom.

0:15 Guest49090: I'm writing a database query function, and the parameter is optional, how to deal with the sql condition.

0:15 (defn query [& params]

0:16 (jdbc/query (connection) ["select ........ "]

0:16 jeaye: Guest49090: Depends what params are.

0:16 Guest49090: how to deal with the 'where' part, is there a library to use ?

0:17 {:code "xx" :name "yy"} => "where code<@?:ltree and name like %?%

0:21 owlbird: I have tried several libs, but they doesn't support sql grammar like "?::ltree", so I have to built the sql manually

0:29 neoncontrails: owlbird: values are immutable in Clojure, so I'm not sure that there is an idiomatic way to mutate a value once it's been set

0:30 You can use an atom to build the query procedurally, though

0:35 owlbird: here's a quick illustration of how I might approach it

0:35 (defn make-query [arg1 arg2] (let [query (atom {:value ""})] (swap! query update-in [:value] str arg1 "::" arg2)))

0:35 ,(defn make-query [arg1 arg2] (let [query (atom {:value ""})] (swap! query update-in [:value] str arg1 "::" arg2)))

0:35 clojurebot: #'sandbox/make-query

0:36 neoncontrails: ,(make-query "something?" "ltree")

0:36 clojurebot: {:value "something?::ltree"}

0:37 neoncontrails: Combine with a dispatch procedure for best results

1:19 kurofune: Does anybody know why lein upgrade is says "Couldn't find project.clj, which is needed for upgrade" when I run it outside of a project? I want to upgrade it globally.

4:24 jonathanj: i don't quite understand what the value of promise-chan is, would someone mind explaining it like i'm five?

4:36 kungi: How can I format a #inst Timestamp in ClojureScript properly?

4:40 raspasov: jonathanj: it allows you to have multiple "things" (threads, go loops, etc) waiting on one thing to complete, i.e. the promise chan

4:40 (def p-chan (promise-chan))

4:41 ashwink005: the for function in clojure.. gives a lazy sequence

4:41 raspasov: (>!! p-chan :cool)

4:41 (<!! p-chan) => :cool

4:41 (<!! p-chan) => :cool

4:41 ashwink005: does that mean it has a caveat?

4:41 raspasov: etc, you can get :cool infinite amount of times

4:41 jonathanj: raspasov: and if you put another value?

4:41 does the output value change? or is that an error?

4:42 kungi: ashwink005: for is more like a list comprehension than a for loop in clojure. If you need side effects have a look at doseq

4:42 oddcully: kungi: with (.format f dt) where f is e.g. (DateTimeFormat. "yyyy-MM-dd HH:mm")

4:42 raspasov: jonathanj: (>!! p-chan :bla) => true

4:42 but doesn't change the output

4:42 (<!! p-chan) => :cool

4:42 kungi: oddcully: thank you

4:42 oddcully: kungi: if there is a log online for #clojurescript then there is a refheap from me two days ago

4:43 jonathanj: raspasov: i understand, thanks for explaining!

4:43 oddcully: kungi: DTF is (:import [goog.i18n DateTimeFormat])

4:43 ashwink005: kungi, I meant if I give it a large seq to evaluate, will it endup giving me like only 32 of the results?

4:43 i.e. a lazy evaluation

4:43 kungi: ashwink005: initially yes

4:44 ashwink005: kungi, how do I force a complete evaluation?

4:44 kungi: ashwink005: doall

4:44 ashwink005: eeash that was simple :P thanks :)

4:46 kungi: oddcully: Do you happen to know reagent-forms a little?

5:19 lgrapenthin: how can I use a javascript library that uses require and module.exports= in ClojureScript?

5:20 i have tried foreign-libs but I get a "require is not defined" error in the console

5:28 ashwink005: how can I create a list using network calls?

5:28 calls being made using some data in another list

5:33 powered: what do you mean ashwink005 ?

5:34 ashwink005: powered, I am confused as to what is the best method to create a sequence and return it, where network calls are required

5:34 since network calls can give exceptions etc, I need to surround it in try catch

5:35 and I can't recur in a try catch

5:46 powered: you can call a function and recur in that function right? then you call this function in a try-catch clause

5:47 it might also be a middleware feature

7:07 necronian: I started an irc library using core.async https://gitlab.com/necronian/ircurple it wraps java socket i/o in channels and processes incoming messages with some middleware

7:08 I stalled on implementing error handling. To send a message I just put it onto the out channel which returns succees even if later the server returns an error

7:09 How, for instance would I write a command to set the user NICK and return an error if it is already taken. What I wrote in fact seems to preclude that possibility.

7:19 mungojelly: necronian: maybe like give a promise of success that's actually an error sometimes when it's realized, sounds like an awesome library btw i'd use that

7:24 kungi: Is there a function for moving keys in a map to a nested map (f {:a :b :c} [:b :c] :nested-key) => {:a :nested-key {:b :c}}?

7:26 necronian: mungojelly: I'll have to look into that, although it sounds complicated. I would probably have to keep track of a lot of state, the protocol rarely tells you if something succeeded either it worked and nothing happens or it sends an error message.

7:29 mungojelly: i'm mildly skeptical of this silence=success plan in general, maybe there should be stdsuccess

7:33 snowell: ,(defn nested [m ks nest] (reduce dissoc (assoc m nest (select-keys m ks)) ks)) ; <--- kungi

7:33 clojurebot: #'sandbox/nested

7:34 snowell: ,(nested {:a 0 :b 1 :c 2} [:b :c] :nested-key)

7:34 clojurebot: {:a 0, :nested-key {:b 1, :c 2}}

7:34 necronian: Maybe create a middleware that sends all errors to an err channel that sent messages can subscribe to. If it doesn't receive a message within a certain timeout then it succeeded.

7:37 kungi: snowell: Sweet :-)

8:19 visof: ,(into [] '(1 2 3))

8:19 clojurebot: [1 2 3]

8:19 visof: ,(into [] '('(1 2 3) '(4 5))

8:19 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

8:19 visof: ,(into [] '('(1 2 3) '(4 5)))

8:19 clojurebot: [(quote (1 2 3)) (quote (4 5))]

8:20 visof: ,(map #(into [] %) (into [] '('(1 2 3) '(4 5))))

8:20 clojurebot: ([quote (1 2 3)] [quote (4 5)])

8:20 visof: ,(map #(vec %) (into [] '('(1 2 3) '(4 5))))

8:20 clojurebot: ([quote (1 2 3)] [quote (4 5)])

8:21 visof: ,(map (fn [l] (into [] l)) (into [] '('(1 2 3) '(4 5))))

8:21 clojurebot: ([quote (1 2 3)] [quote (4 5)])

8:21 visof: how can i convert outer and inner lists to vectors?

8:21 snowell: visof: You can use mapv

8:23 Bronsa: visof: don't nest quotes like that

8:36 powered: how do I do a partial, but fill in elements at the end?

8:37 so (fn f [a b]) reversed => (reverse-partial f b) => (reversed a)

8:39 algernon: #(f % b)

8:40 powered: lol so simple, why didn't I think of that

8:52 mpenet: jonathanj: it's also cheaper in many ways than a regular chan (it's not backed by a queue, makes it a lot simpler)

9:03 lxsameer: guys, how can I write this snippet using java interop ? http://dpaste.com/11XFK0P

9:05 luma: (reify XYZ (method1 [this int1] ...))

9:58 kavkaz: What's the most idiomatic way to see if a collection contains the logical value true?

9:59 And most efficient

10:00 sobel: (some? true coll)

10:00 matthavener: kavkaz: (if (some true? collection) ...)

10:00 taylan: kavkaz: (contains? coll true) ?

10:00 sobel: (some? true? coll)

10:00 kavkaz: Actually I'm performing map with a function returning a logical value on a large collection

10:00 taylan: er, ignore me

10:00 .oO( they could have named that one better )

10:00 kavkaz: Perhaps I should find a built in function that returns true as soon as it sees a logical true value

10:00 mavbozo: ,(map some? [true false nil])

10:01 clojurebot: (true true false)

10:01 sobel: kavkaz: i think 'contains' is the wrong connotation in functional context

10:01 i mean, just destructure if you need 'contians'

10:05 kavkaz: Just ended up using (true? (some #{true} ....))

10:06 Changed #{true} to true?

10:17 sobel: you're right the function some is best for this scenario

13:20 justin_smith: ,(some true? [:a nil true])

13:20 clojurebot: true

13:20 justin_smith: no need for the true? / #{true} combo

13:46 sotojuan: How do I check if Agent.start_link was called? Trying to error out/send a message if it has not

13:46 Sorry wrong channel ~_~

14:08 hlolli: Is it possible to create a map in project.clj and access it's values from a non-project file (core.clj)

14:14 snowell: hlolli: https://github.com/weavejester/environ

14:17 hlolli: ah thanks snowell, I did bump into this name environ few times as I was googling this.

15:49 nanuko: would there be any reason that emacs can’t find cider-debug-defun-at-point?

16:47 justin_smith: nanuko: if your cider version is old

17:50 simon1234: Hi there! I have a question :) I'm loading a namespace manually using read/eval in a loop for every form. At any point an exception can be thrown (RunTime exception might be thrown: example unable to resolve a symbol.) Is there anyway to get which form actually threw the exception? Or to navigate the forms (like going to the parent etc.) around the one that threw it? Thanks a lot!

17:55 rhg135: I think t.a.j exposes this but idk

17:59 simon1234: rhg135: Thanks for your reply, what do you mean by t.a.j ?

18:08 hm clojure.tools.analyzer I guess

18:16 rhg135: Yes, simon1234, that

18:16 The jvm one since I assumed clojure

20:50 celwell: Hello, how can I choose the best server for my production Clojure web service? (jetty, tomcat, nginx, Undertow, http-kit)

20:51 sobel: try them all

21:08 Leonidas: immutant, aleph

21:39 eraserhd: celwell: best for what purpose?

21:40 oh, gone huh.

22:16 BorbaGato: HELP

Logging service provided by n01se.net