This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-05
Channels
- # bangalore-clj (4)
- # beginners (16)
- # boot (4)
- # cljs-dev (1)
- # cljsrn (2)
- # clojure (177)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-russia (41)
- # clojure-spec (3)
- # clojure-uk (21)
- # clojurescript (46)
- # code-art (1)
- # datomic (10)
- # hoplon (125)
- # leiningen (1)
- # luminus (2)
- # lumo (1)
- # off-topic (10)
- # onyx (69)
- # re-frame (22)
- # reagent (4)
- # ring (32)
- # rum (6)
- # specter (2)
- # untangled (5)
@paulocuneo only use one of those (not both), and you have to use a protocol with the deftype as all the mutable fields are private
and as the docs say, only use :unsynchronized-mutable
if you really, really, know what you're doing.
@tbaldridge Thanks! I see now, the reflection error was because of private access field. The field is intended to become read only after i set it so guess is a fair use of mutable.
I'm trying to redefine the logging function a 3rd party library uses during initialisation (for fun mostly). My understanding is that something like
(with-redefs [(var-get (ns-resolve 'third.party.library.core 'log/info)) (fn [& args] (println "foo"))] (library/start))
should work, but I'm getting clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
(defn add-five [a] (+ 5 a))
(with-redefs [add-five (fn [a] (+ 10))] (add-five 5)) ;; 15
(with-redefs [(var-get (ns-resolve *ns* 'add-five)) (fn [a] (+ 10))] (add-five 5)) ;; Error
add-five ;; #object[....]
(var-get (ns-resolve *ns* 'add-five)) ;; #object[..]
`(with-redefs-fn
{(ns-resolve 'library 'log/info)
#(println "foobar")}
(fn [] (library/start)))
I can run this in the REPL with no errors, but it doesn't seem like the log/info function is getting redefined
@kauko Java logging is extremely configurable. But it's a lot of stuff to just explain in chat
So basically ct.logging will use some backends (that can be configured with some xml files, java style) and they'll receive the clj-namespaces as an argument
You can configure which namspace can log which level (warn, info etc) and I believe even redirect just that ns to some other file
I was just trying to see if I could use with-derefs (or something similar) in this case
@abhiroop inner transactions become part of the outer transaction
is there anything like python setup.py develop
in Clojure?
To be more clear, some way to try out a lein plugin from my local checked out version?
@abhiroop not sure what you mean by yield
@andrea.crotti you can do lein install
and that will put the project in your local .m2
folder
ah cool that should it do it thanks @tbaldridge
@tbaldridge I guess I was not very clear. So what I mean by reentrancy is when a thread actually yields
its control flow without the scheduler preempting. And reenter the original control flow. So Thread1 --yields--> Thread2 --reenter--> Thread1. I am not sure if STM supports this kind of interaction, which is common in normal lock based concurrency. Thats why the question.
yes, that is supported.
ref
s are slots where the mutable state being modified is stored. When a transaction commits, it locks all the refs it will operate on and performs the updates. Other transactions can barge the locks, and not all modifications of locks cause rollbacks of other transactions, but that's the general gist.
Other transactions can barge the locks
-> Really? Could you elaborate a little bit on this?
yeah, if it comes time for one transaction to commit, but it can't because another transaction has the refs locked, there's a way for the two threads to communicate. The slow transaction will rollback and the faster one will commit.
the code is here, a quick glance over it may help https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LockingTransaction.java
entry point is here: https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L4980
@tbaldridge I was actually looking at this right now https://github.com/clojure/clojure/blob/f572a60262852af68cdb561784a517143a5847cf/src/jvm/clojure/lang/LockingTransaction.java#L223
Yes found the barge https://github.com/clojure/clojure/blob/f572a60262852af68cdb561784a517143a5847cf/src/jvm/clojure/lang/LockingTransaction.java#L192
So here's the thing that makes Clojure STM different from more mutable languages. The only things that are tracked during a transaction are refs
(and agents, but skip that for now).
Oh I see it now you have a CountDownLatch
which countsdown
for the other thread till 10 seconds
I was looking for a bit more than this communication. For instance, (I am not sure if this is possible) but if 2 core.async
channels exchange messages with each other via a channel rather than just talk about whether the other is holding a lock for too long.
Hi guys. I have just started learning clojurescript and started with a leningen template.
The build was working initially , but now the figwheel repl is stuck and I see Please run lein figwheel to start the ClojureScript compiler and reload the page.
message. Where should I look for errors.
Sorry I posted in the wrong channel.
Let’s say I have the following edn:
{:db/id #db/id[:db.part/user -1000007], :thing/name “thing1”}
And I want to try to convert it and read it with edn/read-string
. I try:
(def tx {:db/id #db/id[:db.part/user -1000007], :thing/name “thing1”}
(edn/read-string (prn-str tx))
Getting an error:
RuntimeException No reader function for tag db/id clojure.lang.EdnReader$TaggedReader.readTagged (EdnReader.java:784)
To avoid the error, I do instead:
(edn/read-string {:readers *data-readers*} (prn-str tx))
;; {:db/id #db/id[:db.part/user -1000009], :thing/name "thing1"}
Can anyone explain, why that works?@ezmiller by default I don't think read-string uses the data-readers found in data-readers. However, that data reader is installed by Datomic, so it works fine if you give it the correct information
Trying to make simple http request, use clj-http
(should I try another library for that?), but got strange ssl error:
1. Unhandled javax.net.ssl.SSLException
Certificate for <api.dribbble.com> doesn't match any of the subject
alternative names: [, ]
Have no idea how to fix that, would be grateful for any advices, guessing, suggestions. Thanks.Make request like that:
(http/get (followers-url given-user)
{:headers {:access_token api-client-access-token}})
@tbaldridge not sure what the data-readers are… is there a doc you could point me to?
@jmsul trace:
AbstractVerifier.java: 165 org.apache.http.conn.ssl.AbstractVerifier/verify
StrictHostnameVerifier.java: 67 org.apache.http.conn.ssl.StrictHostnameVerifier/verify
AbstractVerifier.java: 141 org.apache.http.conn.ssl.AbstractVerifier/verify
AbstractVerifier.java: 114 org.apache.http.conn.ssl.AbstractVerifier/verify
SSLSocketFactory.java: 580 org.apache.http.conn.ssl.SSLSocketFactory/verifyHostname
SSLSocketFactory.java: 554 org.apache.http.conn.ssl.SSLSocketFactory/connectSocket
SSLSocketFactory.java: 412 org.apache.http.conn.ssl.SSLSocketFactory/connectSocket
DefaultClientConnectionOperator.java: 179 org.apache.http.impl.conn.DefaultClientConnectionOperator/openConnection
ManagedClientConnectionImpl.java: 328 org.apache.http.impl.conn.ManagedClientConnectionImpl/open
DefaultRequestDirector.java: 612 org.apache.http.impl.client.DefaultRequestDirector/tryConnect
DefaultRequestDirector.java: 447 org.apache.http.impl.client.DefaultRequestDirector/execute
AbstractHttpClient.java: 884 org.apache.http.impl.client.AbstractHttpClient/doExecute
CloseableHttpClient.java: 82 org.apache.http.impl.client.CloseableHttpClient/execute
CloseableHttpClient.java: 107 org.apache.http.impl.client.CloseableHttpClient/execute
core.clj: 304 clj-http.core/request
Can you make a request to https://api.dribbble.com?
I get an OK from https://api.dribble.com using clj-http 3.3.0
can't believe that dribbble
use invalid certificate. Maybe.. Is there a way to force use that one certificate as correct?
> SunCertPathBuilderException unable to find valid certification path to requested target sun.security.provider.certpath.SunCertPathBuilder.build (SunCertPathBuilder.java:141)
I had this same problem with Let's Encrypt certificates with clj-http 2.0.0; updating fixed it. I would get a Java SSL error but not for other cert authorities
1. Unhandled sun.security.provider.certpath.SunCertPathBuilderException
unable to find valid certification path to requested target
@netsu that's the same error. Your version of clj-http is not updating. How are you doing it?
To be sure that it does not affected by Emacs configuration:
netsu@thinkpad:~/Documents/Projects/dribbble-stats$ lein repl
nREPL server started on port 46073 on host 127.0.0.1 -
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_121-b13
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e
dribbble-stats.core=> (require '[clj-http.client :as http])
nil
dribbble-stats.core=> (http/get "")
SSLException Certificate for <api.dribbble.com> doesn't match any of the subject alternative names: [, ] org.apache.http.conn.ssl.AbstractVerifier.verify (AbstractVerifier.java:165)
dribbble-stats.core=>
`Well, this is identical to my situation with 2.0.0 until I updated to 3.3.0. Maybe start a fresh lein project with the newer version from the beginning?
Huh that's odd, lein install
shouldn't help at all, it installs the current project into your local maven repository. The certificate of https://api.dribble.com/ is invalid, try connecting with any browser or even curl to see!
So if it works for you now without errors, something must be wrong 🙂
If I have this,
weights
=> #{{:name betsy, :weight [12 32]} {:name jake, :weight [1 2 3]} {:name shyq, :weight [342 4 6]}}
, how do I get the name or the map, based on if the weight contains a number?@tmtwd you mean the vector of the weight contains number or the key :weight is keyed to a number?
so for example, if I input 12, I would get {:name betsy, :weight [12 32]}
or something like that
(map :name (filter #(number? (first (:weight %)))
#{{:name 'betsy, :weight [12 32]} {:name 'jake, :weight [1 2 3]} {:name 'shyq, :weight [342 4 6]}}))
(map :name (filter #(some #{6} (:weight %)) #{{:name 'betsy, :weight [12 32]} {:name 'jake, :weight [1 2 3]} {:name 'shyq, :weight [342 4 6]}}))
Hi! I’m trying to make my data structure compatible with map/filter fns, etc. Was trying to extend ISeq but it seemed to still pickup default things for structure.
Here’s my latest code https://gist.github.com/sudodoki/7141ce03f934a47fe13ff41df51387f2
and I get java.lang.ClassFormatError: Duplicate method name&signature in class file
.
Can someone point out how I make this work?
Guys, do transducer achieve the same effect as Elixir's stream module? For example, if I had a range from 0 to a million and I wanted to apply maps and filters to it but without having to pass the result of one map to the next map or filter and so on until the pipeline is done.
I think Elixir calls it lazy enum operations.
This is correct. Effectively, transducers will look like a (map (f (f' (f'' x ))) xs), for example
point being, it is very efficient and doesn't create intermediate sequences, so doesn't unnecessarily copy
After switching from defrecord to deftype, to avoid Don't know how to create ISeq from: TreeNode
I updated code https://gist.github.com/sudodoki/7141ce03f934a47fe13ff41df51387f2 but now I’m getting IllegalArgumentException interface clojure.lang.ISeq is not a protocol clojure.core/extend (core_deftype.clj:769)
anything I’m still missing? 🙇
@bronsa sorry, just got to these parts, and can’t find a good example of deftype with inline method definition w/o protocol, can you give me a hint?
(deftype TreeNode [val l r]
(first [this] (leftmost-in this))
(next [this] (drop 1 (dfs this)))
(more [this] (drop 1 (dfs this)))
(cons [this v] (xconj this v)))
; => ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
seems to be erroring for some other reason…I'm super curious. go/parking threads, is there an equivalent when using libraries like Manifold?
@dominicm there is the concept of deferred
that should kind of being similar iirc..
well, it is more like an abstraction over the specific concurrency primitive you are using
@richiardiandrea it's the parking thread mechanic I'm mostly curious about (or why it doesn't apply)
How can I annotate in Clojure unused function?
Is (def ^{:suppress-warnings "unused"} fn
would be correct analogue for @SuppressWarnings("unused") fn() {
?
What tooling is giving you a warning about it?
There’s no standard for Clojure tooling, as far as I know. For example, Eastwood will give various warnings for unused function arguments and unused locals etc — but you can’t suppress most of those.
And simple Clojure metadata does not correspond to Java annotations so if you’re talking about Java tooling, it’s more complicated than that.
This blog post talks about how to add Java-level annotations to functions in Clojure: http://seancorfield.github.io/blog/2013/05/01/instrumenting-clojure-for-new-relic-monitoring/ — bear in mind that Java annotations are actually types (classes) and the annotations need to happen at the Java level — hence that post uses definterface
and deftype
to expose Java-level methods that can be annotated with Java-level classes.
heh, with pipelining Rapidoid can do ~3M req/s serving JSON API (sort of hello world no other IO) looks promising https://gist.github.com/l1x/2b12971e94d6160ac70f551ab8ee40ff#file-wrk_rapidoid-10g-36core-pipeline3-out
um...wrong chat window?
well, i was looking for a Java HTTP framework that I could use in Clojure that has decent performance and easy to use
so what are you doing that needs 3M req/s ? For more realistic performance numbers there's quite a few good clojure frameworks out there
for example, this one is really fast: https://github.com/pedestal/pedestal/tree/master/samples/fast-pedestal
So, they ran the 3 tests at the end which seem to be identical, and got 3x improvement on the last vs the first. Am I reading it right? @istvan
i have spent some of my time as systems engineer with amazon so we had to understand HTTP really well
most of the projects done in Java are happy with the 30K req/s that you can get with any framework you like, i did not need to look into JVM performance. i just started to discover what can we do to go beyond that sort of performance
So yeah, I guess when you said "decent performance" that made me think "normal performance".
i am curious about this tool though: https://github.com/pinterest/jbender
are there any reasons to use bidi over compojure, other than a preference of data structures over macros?
@albaker A really nice side effect of bidi being data, and we use it regularly at juxt, is that you can walk the data structure to update various leaves. Also, you can easily build things like site maps. The biggest feature though is probably the bi-directional urls. So you never need hard-code a URL again!
@albaker I don't know about bidi, but there is with Pedestal's router. It has several advanced routing algorithms that are much faster than what you will find in other libraries. See the "routers" section here: http://pedestal.io/reference/routing-quick-reference
no idea, never used it, did you run into performance issues that you definitely need to solve? if yes look into it, if not just use what you got. i guess 🙂
@albaker bidi works in cljs too