This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-16
Channels
- # beginners (11)
- # boot (21)
- # cider (12)
- # clara (6)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (62)
- # clojure (137)
- # clojure-austin (5)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-russia (46)
- # clojure-spec (21)
- # clojure-uk (79)
- # clojurescript (56)
- # clr (1)
- # core-typed (1)
- # css (1)
- # cursive (3)
- # datomic (35)
- # docker (2)
- # emacs (20)
- # garden (3)
- # hoplon (8)
- # incanter (3)
- # jobs (12)
- # mount (5)
- # nginx (1)
- # off-topic (71)
- # om (8)
- # om-next (6)
- # onyx (4)
- # perun (3)
- # proton (2)
- # protorepl (5)
- # re-frame (35)
- # reagent (38)
- # ring (5)
- # ring-swagger (12)
- # rum (35)
- # spacemacs (2)
- # specter (5)
- # test-check (6)
- # yada (52)
I wrote
(defmacro defmemo [name args & body]
`(def ~name
(memoize (fn [~@args] ~@body))))
but would be curious to see something that's more through šIs it possible to do a string replace using a symbol as the pattern to match?
@grounded_sage you mean where the name of the symbol is the pattern itself? i don't quite see the value, but yes you can convert a symbol to a string, and a string to a re-pattern:
(clojure.string/replace "123abc789" (-> abc quote str re-pattern) "456")
=> "123456789"
If i'm implementing a tree with Node and Leaf deftypes, how can I write methods that access .-keys for each type of node without reflection? Should I write getter functions for these fields and use those?
oracle jdk SE download page provides 2 version: 8u111 and 8u112. which I should download?
Is there a core function that partitions a collection in two parts based on a predicate?
@mavbozo try #beginners channel
@shooodooken thank you. I will ask there
I already looked at both but they donāt seem to do what I want. Group-by comes closest
E.g. what comes first, all results for which the pred is false or true? With group-by thatās clear without looking at the docs
danielstockton: could probably use a protocolā¦ it sound like youāre wanting some of the features of defrecord
though- so might want to consider using that; otherwise youāll need to implement those bits you need on your deftype
Letās say I have some (def x (reify ....))
in a namespace
ā what would the "fully qualified class nameā of x
be? Tried
but that dināt work...
@martinklepsch reify creates an anonymous instance
Oh, ok š would I use deftype
then?
I use a protocol @rickmoynihan which avoids reflection on methods but not fields apparently, which is why i'm wondering if i should just wrap the field in a lookup method.
Sometimes I think Iām already quite proficient interacting with Java stuff but then things like this come along š
defrecord is another option, i want it to be as performant as possible though
(where you have to pass the fully qualified name of a class as a string to something)
@danielstockton there's no perf difference between deftypes and defrecords -- a defrecord is just a deftype that implements a bunch of default interfaces to behave like a map
if you type-hint, (.-some-field ^ClassName the-type-or-record-instance)
it will not use any reflection
I know @bronsa but i don't know the class at compile time, just trying to remove the reflection warning
im worried i may want different implementations of some of those default interfaces that defrecord already implements
how do you not know the class at compile time if you're doing field access? do you have multiple deftypes with the same field names? in that case a protocol function to access them should be the right abstraction. if using kw access using defrecords is out of the question
yeah, multiple deftypes with same fields...protocol function it is then
so with a (deftype MyThing [])
in com.my-abc
would the fqn be com.my_abc$MyThing
?
ha, should have just tried that. Remember something about inner classes and thought I need the `ā¦ thanks @bronsa
(and sorry for asking really boring questions haha)
Another Java related question: How would I rewrite this to use reify
ā and should I at all?
(proxy [KeyedPooledObjectFactory] []
(makeObject [k] (DefaultPooledObject. (make k)))
(destroyObject [k ^PooledObject o] (destroy k (.getObject o)))
(validateObject [k ^PooledObject o] (validate k (.getObject o)))
(activateObject [k ^PooledObject o] (activate k (.getObject o)))
(passivateObject [k ^PooledObject o] (passivate k (.getObject o))))
I tried something like this but it complains about wrong return types for destroyObject
(should be void is Object)
(reify KeyedPooledObjectFactory
(makeObject [_ k] (DefaultPooledObject. (mk-session k)))
(destroyObject [_ k ^PooledObject o] nil)
(validateObject [_ k ^PooledObject o] nil)
(activateObject [_ k ^PooledObject o] nil)
(passivateObject [_ k ^PooledObject o] nil))
(reify KeyedPooledObjectFactory (makeObject [this k] (DefaultPooledObject. (make k))) ..)
hm, same result for this
(destroyObject ^void [_ k ^PooledObject o] (destroy k (.getObject o)))
that did the trick!
@bronsa Thanks!
um. do we have a rails analog presence
function in clojure?
(presence nil) ; nil
(presence ""); nil
(presence "hi"); "hi"
(presence []); nil etc
to be used like so:
(some->> city presence (str ", and the city is:"))
(defn presence [x] (when (seq x) x))
=> #'user/presence
(presence nil)
=> nil
(presence "")
=> nil
(presence "hi")
=> "hi"
(presence [])
=> nil
How can I compose a regex out of variables?
Does subvec
keep a reference to whole original vector or only to the relevant part?
That is, can I subvec
a needed small piece of data out of a huge vector and don't be worried about retaining the whole huge vector in memory?
Answering myself after some REPL experimentation: subvec
does retain whole original vector in memory.
interesting @dottedmag, i guess it has to as there is no easy clue which parts can be GCed
You think this is something specific to subvec
? I'd expect it to be the same with conj
for example.
So, I suppose it's because subvec
is supposed to be very fast, so there is no overhead of creating a new persistent data structure.
So, if one wants to pick a subrange out of a large vector and discard it, it ought to be done via (vec (subvec largestuff N M))
, which will build a new persistent data structure.
@stijn , thanks, that actually works, however it's tricky to understand that it works like that) also it needs to work only for {}, [] and strings, numbers are ok)
@bronsa Why doesn't (into [] (subvec ov m n))
work? Is it due to fast path in into
which says ah, it's a vector too, let's just not copy anything
?
Interesting. Let me try again, (into [])
kept the whole data structure in memory for me.
After (into [] (subvec a 1 100)) (ns-unmap 'user 'a) (System/gc)
memory is released.
@dottedmag side question, how are you measuring the memory consumption of these things?
@danielstockton Using jmc(1)
@leov: it works for strings because a string is a sequence of characters, if it is empty, it will return nil
@danielstockton Yes. It's a GUI tool which comes with JVM and creates nifty memory/CPU/whatever graphs.
ok, thanks
@dottedmag @danielstockton I dont want to be nitpicking here, but in case someone else reads this: The java mission control comes with the oracle JDK and is bound to the oracle license whereas it is not part of the OpenJDK.
It uses JMX to collect metrics, which is in OpenJDK, so there are probably other similar clients.
VisualVM (http://visualvm.github.io) for example
in Spec, how do I say that a map must have :req
keys and that 2 of their vals depend on eachother ? like, one of the map's vals must be a collection and another one must in a number in the range (count coll)
@dottedmag yep that's done it - thanks so much!
Iām trying to connect to AWS Athena over JDBC (clojure.java.jdbc). Iām getting an error saying Exception in thread "main" com.amazonaws.athena.jdbc.NotImplementedException: Method Connection.prepareStatement is not yet implemented, compiling:(/private/var/folders/h1/pt7t6l9s2bq2zblx4v2mmnnh0000gn/T/form-init4382409266245799902.clj:1:125)
Is there a way to query jdbc without using prepareStatement? Iām using (query db [āSELECTā¦ā] {:row-fn :cost})
@erikcw Looking at the source, one way might be to try and use db-do-commands, looks like it uses Statement https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L760
I would assume the Athena JDBC library provides a way to create a PreparedStatement
object via some subclass? If so, you can pass that into query
as part of the vector, so it doesnāt need to call prepareStatement
itself.
@brabster Yeah, youāre going to run foul of what you can / canāt do with the various underlying JDBC execute functions.
This might be helpful... someone already did Athena from Clojure https://github.com/mikeplavsky/athena-cmd/blob/master/src/athena_cmd/core.clj
@seancorfield good idea on looking for other ways to create a preparedstatement but I don't see anything in the jar that looks like one. I'm guessing it's just not implemented yet at all
Looks like it calls .createStatement
rather than .prepareStatement
so that would be the path Iād suggest ā but that looks like a plain Statement
rather than a PreparedStatement
so Iām not sure java.jdbc will recognize it.
(since it specifically tests instance? PreparedStatement
)
does the rich hickey/ cognitect crew have anything to say on the subject of release management? I'm moving into the role of "release manager"/"please help us fix our release process" person at my company. I'm looking for role models for modern release management practices.
you could look into @mtnygard blog posts: http://blog.cognitect.com/blog/?author=538e1607e4b0e4caa9812f47
not sure if they're about release management per se, but in the vicinity for sure
@tjtolton If you havenāt read Jez Humble & Dave Farleyās book āContinuous Deliveryā that would be a great place to start.
I'll look into that book and your blog, thanks @mtnygard, and @pesterhazy!
donāt forget mtnygards own book on the subject: https://www.amazon.com/Release-Production-Ready-Software-Pragmatic-Programmers/dp/0978739213/
@tjtolton one of the key principles is ābuild-onceā deploy everywhere. The Google SRE book also has a few chapters you might find helpful although donāt get overwhelmed by it. Pick the things you think will fit and benefit your org most.
seconding michael's book, it's def worth reading
What's the easiest way to pick up a build time env var and pack it up into my jar so that I can use it in a function?
It's just going to be write the build number to a file during build and read that at runtime isn't it :)