#clojure logs

2015-10-29

00:08Guest49090how to change a variable value , defined by let
00:15jeayeGuest49090: Do so in a loop or recurse or, if you absolutely must, use an atom.
00:15Guest49090I'm writing a database query function, and the parameter is optional, how to deal with the sql condition.
00:15Guest49090(defn query [& params]
00:16Guest49090 (jdbc/query (connection) ["select ........ "]
00:16jeayeGuest49090: Depends what params are.
00:16Guest49090how to deal with the 'where' part, is there a library to use ?
00:17Guest49090{:code "xx" :name "yy"} => "where code<@?:ltree and name like %?%
00:21owlbirdI have tried several libs, but they doesn't support sql grammar like "?::ltree", so I have to built the sql manually
00:29neoncontrailsowlbird: 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
00:30neoncontrailsYou can use an atom to build the query procedurally, though
00:35neoncontrailsowlbird: here's a quick illustration of how I might approach it
00:35neoncontrails(defn make-query [arg1 arg2] (let [query (atom {:value ""})] (swap! query update-in [:value] str arg1 "::" arg2)))
00:35neoncontrails,(defn make-query [arg1 arg2] (let [query (atom {:value ""})] (swap! query update-in [:value] str arg1 "::" arg2)))
00:35clojurebot#'sandbox/make-query
00:36neoncontrails,(make-query "something?" "ltree")
00:36clojurebot{:value "something?::ltree"}
00:37neoncontrailsCombine with a dispatch procedure for best results
01:19kurofuneDoes 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.
04:24jonathanji don't quite understand what the value of promise-chan is, would someone mind explaining it like i'm five?
04:36kungiHow can I format a #inst Timestamp in ClojureScript properly?
04:40raspasovjonathanj: it allows you to have multiple "things" (threads, go loops, etc) waiting on one thing to complete, i.e. the promise chan
04:40raspasov(def p-chan (promise-chan))
04:41ashwink005the for function in clojure.. gives a lazy sequence
04:41raspasov(>!! p-chan :cool)
04:41raspasov(<!! p-chan) => :cool
04:41raspasov(<!! p-chan) => :cool
04:41ashwink005does that mean it has a caveat?
04:41raspasovetc, you can get :cool infinite amount of times
04:41jonathanjraspasov: and if you put another value?
04:41jonathanjdoes the output value change? or is that an error?
04:42kungiashwink005: for is more like a list comprehension than a for loop in clojure. If you need side effects have a look at doseq
04:42oddcullykungi: with (.format f dt) where f is e.g. (DateTimeFormat. "yyyy-MM-dd HH:mm")
04:42raspasovjonathanj: (>!! p-chan :bla) => true
04:42raspasovbut doesn't change the output
04:42raspasov(<!! p-chan) => :cool
04:42kungioddcully: thank you
04:42oddcullykungi: if there is a log online for #clojurescript then there is a refheap from me two days ago
04:43jonathanjraspasov: i understand, thanks for explaining!
04:43oddcullykungi: DTF is (:import [goog.i18n DateTimeFormat])
04:43ashwink005kungi, I meant if I give it a large seq to evaluate, will it endup giving me like only 32 of the results?
04:43ashwink005i.e. a lazy evaluation
04:43kungiashwink005: initially yes
04:44ashwink005kungi, how do I force a complete evaluation?
04:44kungiashwink005: doall
04:44ashwink005eeash that was simple :P thanks :)
04:46kungioddcully: Do you happen to know reagent-forms a little?
05:19lgrapenthinhow can I use a javascript library that uses require and module.exports= in ClojureScript?
05:20lgrapenthini have tried foreign-libs but I get a "require is not defined" error in the console
05:28ashwink005how can I create a list using network calls?
05:28ashwink005calls being made using some data in another list
05:33poweredwhat do you mean ashwink005 ?
05:34ashwink005powered, I am confused as to what is the best method to create a sequence and return it, where network calls are required
05:34ashwink005since network calls can give exceptions etc, I need to surround it in try catch
05:35ashwink005and I can't recur in a try catch
05:46poweredyou can call a function and recur in that function right? then you call this function in a try-catch clause
05:47poweredit might also be a middleware feature
07:07necronianI 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
07:08necronianI 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
07:09necronianHow, 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.
07:19mungojellynecronian: 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
07:24kungiIs 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}}?
07:26necronianmungojelly: 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.
07:29mungojellyi'm mildly skeptical of this silence=success plan in general, maybe there should be stdsuccess
07:33snowell,(defn nested [m ks nest] (reduce dissoc (assoc m nest (select-keys m ks)) ks)) ; <--- kungi
07:33clojurebot#'sandbox/nested
07:34snowell,(nested {:a 0 :b 1 :c 2} [:b :c] :nested-key)
07:34clojurebot{:a 0, :nested-key {:b 1, :c 2}}
07:34necronianMaybe 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.
07:37kungisnowell: Sweet :-)
08:19visof,(into [] '(1 2 3))
08:19clojurebot[1 2 3]
08:19visof,(into [] '('(1 2 3) '(4 5))
08:19clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
08:19visof,(into [] '('(1 2 3) '(4 5)))
08:19clojurebot[(quote (1 2 3)) (quote (4 5))]
08:20visof,(map #(into [] %) (into [] '('(1 2 3) '(4 5))))
08:20clojurebot([quote (1 2 3)] [quote (4 5)])
08:20visof,(map #(vec %) (into [] '('(1 2 3) '(4 5))))
08:20clojurebot([quote (1 2 3)] [quote (4 5)])
08:21visof,(map (fn [l] (into [] l)) (into [] '('(1 2 3) '(4 5))))
08:21clojurebot([quote (1 2 3)] [quote (4 5)])
08:21visofhow can i convert outer and inner lists to vectors?
08:21snowellvisof: You can use mapv
08:23Bronsavisof: don't nest quotes like that
08:36poweredhow do I do a partial, but fill in elements at the end?
08:37poweredso (fn f [a b]) reversed => (reverse-partial f b) => (reversed a)
08:39algernon#(f % b)
08:40poweredlol so simple, why didn't I think of that
08:52mpenetjonathanj: it's also cheaper in many ways than a regular chan (it's not backed by a queue, makes it a lot simpler)
09:03lxsameerguys, how can I write this snippet using java interop ? http://dpaste.com/11XFK0P
09:05luma(reify XYZ (method1 [this int1] ...))
09:58kavkazWhat's the most idiomatic way to see if a collection contains the logical value true?
09:59kavkazAnd most efficient
10:00sobel(some? true coll)
10:00matthavenerkavkaz: (if (some true? collection) ...)
10:00taylankavkaz: (contains? coll true) ?
10:00sobel(some? true? coll)
10:00kavkazActually I'm performing map with a function returning a logical value on a large collection
10:00taylaner, ignore me
10:00taylan.oO( they could have named that one better )
10:00kavkazPerhaps I should find a built in function that returns true as soon as it sees a logical true value
10:00mavbozo ,(map some? [true false nil])
10:01clojurebot(true true false)
10:01sobelkavkaz: i think 'contains' is the wrong connotation in functional context
10:01sobeli mean, just destructure if you need 'contians'
10:05kavkazJust ended up using (true? (some #{true} ....))
10:06kavkazChanged #{true} to true?
10:17kavkazsobel: you're right the function some is best for this scenario
13:20justin_smith,(some true? [:a nil true])
13:20clojurebottrue
13:20justin_smithno need for the true? / #{true} combo
13:46sotojuanHow do I check if Agent.start_link was called? Trying to error out/send a message if it has not
13:46sotojuanSorry wrong channel ~_~
14:08hlolliIs it possible to create a map in project.clj and access it's values from a non-project file (core.clj)
14:14snowellhlolli: https://github.com/weavejester/environ
14:17hlolliah thanks snowell, I did bump into this name environ few times as I was googling this.
15:49nanukowould there be any reason that emacs can’t find cider-debug-defun-at-point?
16:47justin_smithnanuko: if your cider version is old
17:50simon1234Hi 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:55rhg135I think t.a.j exposes this but idk
17:59simon1234rhg135: Thanks for your reply, what do you mean by t.a.j ?
18:08simon1234hm clojure.tools.analyzer I guess
18:16rhg135Yes, simon1234, that
18:16rhg135The jvm one since I assumed clojure
20:50celwellHello, how can I choose the best server for my production Clojure web service? (jetty, tomcat, nginx, Undertow, http-kit)
20:51sobeltry them all
21:08Leonidasimmutant, aleph
21:39eraserhdcelwell: best for what purpose?
21:40eraserhdoh, gone huh.
22:16BorbaGatoHELP