This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-15
Channels
- # adventofcode (1)
- # beginners (79)
- # boot (23)
- # cider (15)
- # cljs-dev (14)
- # cljsrn (27)
- # clojars (4)
- # clojure (172)
- # clojure-dusseldorf (23)
- # clojure-india (2)
- # clojure-italy (1)
- # clojure-nl (23)
- # clojure-russia (43)
- # clojure-spec (29)
- # clojure-uk (70)
- # clojurescript (97)
- # clr (8)
- # cursive (10)
- # datomic (69)
- # events (3)
- # garden (12)
- # hoplon (120)
- # immutant (34)
- # lein-figwheel (9)
- # leiningen (4)
- # off-topic (4)
- # om (10)
- # onyx (51)
- # rdf (1)
- # re-frame (15)
- # reagent (23)
- # ring-swagger (8)
- # test-check (3)
- # untangled (96)
- # yada (1)
a lein....why you gotta be so dirty
no sure what it is with that tool, but about 2-3 times a week I hear a client, co-worker or someone here on this list have a problem fixed by lein clean
This package’s function is failing when included in a defmacro
and called from CLJ or CLJS, but works up to the last to-hiccup
step: https://github.com/theJohnnyBrown/endophile/issues/11
I need some architecture assistance. I'm using yogthos' clj-log in a ring app, but need to be able to specify a function to create the log's data structure. The method that library uses to do that is here: https://github.com/yogthos/clj-log/blob/master/src/clj_log/core.clj#L25-L30
I'm wanting to either fork and expand on this library or write my own. In Python (my "native" language), I'd create a Logger class with a default implementation of the make-message
method, then subclass it to implement custom functionality. I'm confused about how to do it in Clojure. Obviously, subclassing it isn't correct.
I want to be able to define the make-message
function once, and have it applied everywhere in my application. The only way I know to do that would be to create a namespace for my logging tool - say, myapp.logging
- implement the log
function there, then import from that namespace everywhere in my app. Is there a better way?
@lyndsysimon what don't you like about that method?
@lyndsysimon incidentally, I'm not really using or really maintaining clj-log aside from taking prs, I'd be happy to transfer it over if you plan on using it/working on it
hi, someone online who can help a bit with java interop? Java:
Settings settings = Settings.builder()
.put("cluster.name", "myClusterName").build();
TransportClient client = new PreBuiltTransportClient(settings);
i tried quite a few things with ->
or doto
, but in the end i always get No matching ctor
(def client
(-> (Settings/builder)
(.put "cluster.name" "elasticsearch_pair")
(.build)
(PreBuiltTransportClient.)))
last time I looked at the es java api (this was several years ago) it changed pretty often
maybe check to see if whatever docs / example code you are following matches the version you are using
@peterromfeld Perhaps a type hint is required?
(def client
(let [^Settings s (-> (Settings/builder) (.put ...) (.build))] (PreBuiltTransportClient. s)))
thanks, ive lunch break now.. will try when i get back to office and let you know
@yogthos Good to know. I'll let you know if I decide to head that direction.
@gfredericks I don't like that it doesn't seem very reusable.
@lyndsysimon sounds good
@seancorfield no luck 😞
i tried again also with doto
and also with (def ^TransportClient client ...
but still only get No matching ctor
Do you have the code up on GitHub somewhere that we can play with to try to help fix it?
one sec
'k ... cloning ..
Well, I can repro your problem 🙂
Trying to find better documentation of that PreBuiltTransportClient class...
OK, it's because it's a variadic Java method and takes an optional array of plugins as the second argument.
i remember last time i struggled with java interop i had to pass an empty array
(-> (Settings/builder)
(.put "cluster.name" "elasticsearch_pair")
(.build)
(PreBuiltTransportClient. (into-array Class [])))
awesome thanks!
I couldn't resist a puzzle like that 🙂
i have no java knowledge and always struggle if i have to dive into this world 😕
thanks again!
Actually you can just use an empty vector -- don't need (into-array Class [])
, just []
will do
Oh, just noticed you linked to the JavaDocs... it was below the fold on my laptop... I should have scrolled down 😐
btw the rest was also not perfect documented but i figured it out 😉 works like a charm, i can just pass normal maps without any json encoding 😄
discovered this via
(spec/conform :clojure.core.specs/binding-form '{:as m})
;; => [:seq {:elems [[:seq {:as {:as :as, :sym m}}]]}]
@noprompt that's expected. What did you assume the output to be?
Hi, everyone. I have a small question. I have a vector of functions [f1 f2 f3] and I have a vector of arguments [a1 a2 a3], which function would produce [(f1 a1) (f2 a2) (f3 a3)] ? I guessed (map apply [f1 f2 f3] [a1 a2 a3]) but it doesn't work: Don't know how to create ISeq from: java.lang.Long
@rauh @fellshard thanks, it worked:)
do I understand it correctly that (shutdown-agents)
shuts down the thread pool backing agents and futures but it actually doesn't wait for the future threads to complete?
I'm looking at mongo's profiling output, which seems to be different for different operations. It outputs a JSON that is of nested and always different structure. Thanks to monger I have the profile output ready in clojure's data structures - a list of these weird nested maps. Is there some simple way to find the common structure of these maps? Like (common-structure '({:foo {:bar 1 :baz 2} :one {:two 2 :three 3}} {:foo {} :one {:two 2}}) --> [:foo [] :one [:two]]
is there way to precompile or configuring project.clj file to do so, hiccup clj files ?
sickill that's a close one, unfortunately it diffs the values as well, I'm only interested in the strucuture, i.e. the keys
@xifi No on a hash-map, I'm guessing yes on a sorted-map or an array-map
I'm dealing with deploying a ring app, and need to address credentials management. Elsewhere, we're using credstash, but I'm not seeing anyone talking about using it with Clojure. Does anyone have experience using credstash in Clojure?
@lyndsysimon I've seen KMS used directly from Clojure, and reading the encrypted form from a config file. What kind of integration would you expect from credstash? It doesn't expose an API that I can see, and is a CLI application?
My first thought was just to shell out to it to get the creds I need. Not elegant, but would work.
Thanks @dominicm. I'll look into amazonica; it's already in the project for something else anyhow.
As usual, it looks like Clojure just does it, simply, instead of dealing with integrating some other technology.
@lyndsysimon Yep. That's pretty much it 🙂
when i hava a function (defn refresh-address [id & {:keys [line1 line2 city postcode country]}]
it expects to be called like (refresh-address 234435 :line1 “ASdf”)
which is fine, but sometimes i would like to call it (refresh-address 12323 myObject)
and have it pick out keys from inside.
how can i have that?
@karol.adamiec - I think you could use a multimethod. I'm still a fair green Clojurian, so take my advice for what it is.
By "object", i assume you mean a hashmap?
@karol.adamiec You need to use apply
@karol.adamiec ^^ That's what you want I believe.
@dominic I think @karol.adamiec is asking how to write a method that will take arguments in either form, not how to call the method using its existing signature.
To my knowledge, this isn't possible with Clojure's arity detection, as it isn't typed. You would need to do an if inside the body of the function.
Generally, I don't find that I need this though, when I want to use the hashmap form, it's because I've built it programatically, and not because of requiring that abstraction.
@dominicm you are right i want to call a fn with a map because that is what i get from other place
(refresh-address 234 (apply concat {:line1 "asdf"}))
throws ;/ @dominicm
IllegalArgumentException No value supplied for key: clojure.lang.LazySeq@d04b25e7 clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
(apply refresh-address 234 (apply concat {:line1 "SDf"}))
that works 🙂, cheers!
hey, is clojurebot accessible to anyone? or it's restricted?
@saeidscorp just prefix any clojure expression with /clj
@pesterhazy so my expectation is (= true (let [{:as m} [1 2 3]] (map? m)))
.
the semantics are just confusing. there’s effectively no difference between {:as m}
and [:as m]
.
of course, i’ve looked at how various destructuring notations are “expanded” but i’m not sure these are good semantics.
and i’ve known about this for a while. it wasn’t until last night when working a macro when began wanting to know why these are the semantics in the first place.
hello all, is there any library that we can execute functions in concurrency and call a handler after all execution be called?
@agile_geek thanks man!
@saeidscorp you're welcome
(let [c1 (future (do ,,, 1))
c2 (future (do ,,, 3))
c3 (future (do ,,, 3))]
(+ @c1 @c2 @c3))
;; => 7
(let [c1 (future (do (Thread/sleep 3000)
(System/currentTimeMillis)))
c2 (future (do (Thread/sleep 1000)
(System/currentTimeMillis)))
c3 (future (do (Thread/sleep 2000)
(System/currentTimeMillis)))]
[@c1 @c2 @c3])
;; => [1481822280122 1481822278122 1481822279123]
Given a valid form, what would be the approach to find all atoms used in the form . Any pointers please?
are you using a particular library? are forms a particular kind of custom datastructure that your program uses? (apologies if your question is regarding something discussed earlier and i’m missing context)
http://stackoverflow.com/a/11782628/7293650 seems like a reasonable way of checking if something’s an atom, if that’s helpful
I meant a valid sexp, yes.. read a user input string (a clj expression) as a data structure and find the atoms used in the expression
gotcha - off the top of my head, i see two approaches:
1) figure out how to get a list of all of the symbols foo
, bar
, baz
, etc used in the expression and then check their values in the way described in that stackoverflow post (simple but not 100% thorough - if the expression includes a call to a function like use-hidden-atom
that uses some atom not mentioned in the expression itself, you won’t find that atom)
2) reagent solves a similar problem by having a custom record that behaves just like an atom, but which sort of “registers” itself as having been used whenever it’s dereferenced
perhaps there are other, better options too, those are just the main ones that come to my mind 🙂
Anyone know a way to measure the size of a ref? or atom?
`
(def a (atom []))
(def b (atom {}))
(let [form '(f [a b c])]
(reduce
(fn [m x]
(or (when-let [var (and (symbol? x)
(resolve x))]
(when (instance? clojure.lang.Atom @var)
(assoc m var x)))
m))
{}
(tree-seq coll? seq form)))
that doesn’t happen in the async case, so because of laziness, your side effect doesn’t go off
this is why entering (range)
into a REPL will lock it up, whereas you can do (def foo (range))
in your code just fine, etc
@cdine the use of tree-seq
will produce a sequence of all branches and their children. we can then use reduce
to filter out symbols that can be resolved to a var which currently points to an atom.
@pishty maybe this will be a helpful illustration:
cljs.user=> (defn foo [a-number] (println a-number))
#'cljs.user/foo
cljs.user=> (map foo [1 2 3])
1
2
3
(nil nil nil)
cljs.user=> (let [bar (map foo 123)]
#_=> nil)
nil
@cdine you can extended this technique in several interesting ways like locating free variables, etc.
when i write (map foo [1 2 3])
into the REPL, it prints out the value of that expression (that’s P in REPL), which causes the lazy map
expression’s value to be fully realized
but when i eg define a variable named bar
and don’t cause the REPL to print it, it stays lazy / unrealized
thank u so much for the explanation @jrheard , i think i understand. does this mean whenever we want to insert a list into a db we have to make sure that the list is fully realized
it sorta depends - i think the issue here is that you’ve got this function:
(defn upsert-into-db [reddits]
(map #(upsert-record %) reddits))
and its purpose is to cause side effects to happen, but it’s implemented using map
, which is lazyso the issue isn’t whether or not reddits
is a lazy sequence/list/whatever, it’s that your function is supposed to run side effects over its inputs but the function itself is lazy so it doesn’t always do that
i think the solution is to make sure that your side-effecting functions aren’t implemented that way - eg switching the map
to a mapv
like mpenet suggests will accomplish that here
if your side-effecting function is “eager” (the opposite of lazy), it shouldn’t matter whether or not its inputs are lazy, it’ll force them all to be realized
thank u again @jrheard i think i understand what i was doing wrong in this instance but i think i need to read more on lazy and eager functions in clojure and when to use one over the other
my function takes a list of foo
s and returns a bar
but it’s lazy, my other function has the exact same inputs and outputs but it’s eager, etc
laziness is primarily useful if you want to write a program that operates on a huge or even infinite amount of data and doesn’t immediately fall over
@jrheard and @noprompt , thanks for the overwhelming responses.. I will give this a shot when I get back to work.. But thanks again..
any suggestions on a good "learning clojure" book for an experienced delphi / python / F# developer? would like to use clojure to build some dashboard style UI's to visualize financial simulation results at work, most likely with D3. But need to walk before trying to run. 😉
I liked the looks of Living Clojure, but it may be a bit out of date as it's using enfocus for the UI chapter
@genec: I don't think Living Clojure is out of date - I would try using it to learn, then move on to the tools that make the most sense for your use case.
@shaun-mahood thanks, do you think it's a good book to start out with? any other suggestions?
@genec: Lots of good resources at http://clojure.org/community/resources - it seems like Living Clojure and Clojure for the Brave and True both receive quite a few recommendations as a first Clojure book
@shaun-mahood great, thanks. that's pretty much the 2 books that looked good to me too. I'll take a look at the resources too.
Does anyone know if you can do this: https://blog.heroku.com/postgres-essentials#track-the-source-of-your-queries with clojure.java.jdbc or other Clojure DB libs?
@danielcompton The mentioned libs just append a sql comment with location to each query
E.g. Hugsql could do this, but I don't think there is a way for java.jdbc to get file & location of the function call
probably not without macros AFAIK
Yeah with macros it would be possible
(defn query' [db sqlvec file {:keys [line column]}]
(let [sqlvec (update sqlvec 0 str (format " -- %s on line %s, column %s" file line column))]
sqlvec))
(defmacro query [db sqlvec]
`(query' ~db ~sqlvec ~*file* ~(meta &form)))
(comment
(query nil ["SELECT * FROM foo"])
;; => ["SELECT * FROM foo -- /tmp/boot.user7194000466341961541.clj on line 53, column 3"]
)
Oh, fireplace repl messes up file in that example