This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-17
Channels
- # admin-announcements (103)
- # beginners (4)
- # boot (101)
- # cider (64)
- # clojure (126)
- # clojure-australia (1)
- # clojure-berlin (21)
- # clojure-china (1)
- # clojure-dev (11)
- # clojure-germany (13)
- # clojure-india (1)
- # clojure-italy (20)
- # clojure-japan (43)
- # clojure-poland (7)
- # clojure-russia (9)
- # clojure-spain (4)
- # clojure-uk (10)
- # clojurescript (152)
- # core-async (2)
- # css (51)
- # editors (25)
- # events (2)
- # instaparse (17)
- # jobs (1)
- # ldnclj (50)
- # om (7)
- # reactive (7)
- # reading-clojure (1)
- # reagent (1)
- # remote-jobs (1)
Having trouble setting the logback.configurationFile
via :jvm-opts in a profile within my project.clj
@devn IIRC there is different metadata you can attach to keys in project.clj
to control how they’re merged with default ones
does anyone know why partition-all has an ArrayList managing the state in the transducer version? https://github.com/clojure/clojure/blob/clojure-1.7.0-RC1/src/clj/clojure/core.clj#L6943
as far as I understand it wouldn’t be safe to use partition-all in a core.async context e.g.
@stijn: partition-by
also uses ArrayList
, I was wondering the same and re-wrote it with volatile a few weeks ago: The volatile was about half as fast
@stijn: All the volatile usages for transducers don't hold a collection but often only a flag or a counter. Only distinct
holds a volatile set.
hmm, I see, but that means that if your operation gets scheduled on another thread, it might not see the correct value of the partition built so far
@stijn: Not sure what you mean with that. Transducers are not parallel at all currently. And you still get a (vec)
view of it when you actually get the result.
@rauh: no they’re not parallel, but if you put a transducer on a core.async channel, is there a guarantee that it’s always executed on the same thread?
@rauh: otherwise it might be the case the value of your arraylist is not visible on the other thread (when running on multiple cores)
a volatile synchronizes the write between threads, a java Vector does the same, but ArrayList doesn't
@stijn: You arent' allowed to share the transducer like that. I believe it's noted in Rich's "inside transducer" video
@rauh: it’s not sharing the transducer, you set the transducer on a channel, which will instantiate it. the only process having access to the transducer state is that particular channel.
but in between receiving values which are stored in the arraylist the executing thread might change
it’s not about concurrent access, it’s about having the value visible to the currently executing thread on the jvm
Yeah I understand what you mean, but once you instantiate the transducer with the reducing function you'll have to keep it to yourself. Check out the last sentence on: http://clojure.org/transducers
no, they can
the ArrayList reference doesn't change, so it doesn't need to be volatile
that is, it is the stateful container
an alternative would be a (volatile []) but that would be much slower
@alexmiller: and a write to the list is being flushed to memory always?
yes, although I think the question you're asking is whether visibility is guaranteed across threads right?
I would say yes and if not it's a bug :)
in the case of a channel transducer, the transducer is being applied inside the channel, under a lock and that lock will force happens-before
@alexmiller: is there any particular reason why distinct uses a volatile set instead of a mutable java set?
java sets use java hashing
but we want clojure hashing
the first impl did (incorrectly) use java hashing :)
we had a discussion at yesterday’s BeClojure meetup where the ArrayList came up (as I copied the code to create a partition-all that allows stepping)
escherize: probably best not to think about it. Or at least make sure you sit down when you do.
@escherize: sets are unordered, so it makes sense that won’t work
just as a thought exercise, what would be the best way to check that collections contain the same elements? #(= (vec %1) (vec %2))
#(= (set %1) (set %2))
dnolen: i know, I was more thinking that it’s not immediately apparent because it’s not an error to do that, despite it not making much sense. and for the toy data example the expected result (if it had been a sequence) was found
Hi, I want to provide a java wrapper class for my clojure project. I'm wondering if leiningen supports building and unit testing the java wrapper class. Would this be simple to do? No, I haven't tried yet (sorry).
@em Leiningen can compile Java sources (`:java-source-paths` in project.clj I think). Not sure what testing would involve.
Thanks @stuartsierra. Would the dependency (and thus the build order) from java code to clojure be a problem? All samples I've seen so far have the dependency the other way.
@em I think the default is to compile the Java first. Don't know if that can be changed.
you can hack it with :prep-tasks in leiningen I think
@juhoteperi: it was my fault in the end — got it working today and it’s AMAZING!
@txus: Good to hear
Clojure 1.7.0-RC2 is now available https://groups.google.com/d/msg/clojure/0iCTNg9RNHw/STxq3DVq_U4J
Question: if I write a library using cljc files, will that library be completely incompatible when consumed by projects with clojure <= 1.6? Or will some compilation step during the jarring / deploying eliminate that specific concern?
it is incompatbile
cljc and reader conditionals will only work on 1.7+
someone somewhere (forget where now) suggested backporting (only) reader conditionals to a 1.6.1. I'm not eager to take that on but if there was a widespread desire for it, that might be an option.
Man. I was hoping that while deploying something to clojars, it would compile to .class
files, at which point it wouldn't matter whether it came from clj or cljc
if you aot to .class, then you should actually be ok
.class is preferred to clj or cljc during load
Does that happen automatically during lein deploy clojars
? (noob jar question)
you would have to set up your lein project for aot
"lein sample" and grep for aot
Any prominent downsides of doing that? Lamer stack traces, etc?
well, you'd be compiling with 1.7
it's possible that you would create code that depended on 1.7 at runtime as well
that is, calling into functions that don't exist in the 1.6 runtime
Wouldn't such issues appear anyway if I just distribute source?
generally, no if you avoid using functions that are new in 1.7
AOT-compiled .class files contain references to internal methods in the Clojure runtime.
calls to RT etc
OK, that makes sense.
we do make an effort not to break or remove existing methods as we move forward, but of course if you compile to new things that are added, then the old RT can
t have those
so old compiled .class can run on new runtime but new compiled .class can't necessarily run on old runtime
Got it
Thanks Alex (+ Stuart cameo)
that said, the diffs in this area are small and you might get away with it :)
but we don't test for it
I'm trying to figure out the best way to target clj and cljs from instaparse.
With cljx apparently now deprecated, I'm not sure what's left (since cljc is incompatible with <1.7 and that compatibility is important to us)
cljx is a source-code transformation, so I expect it will continue to work for a while.
I looked at the diffs from 1.6 to 1.7 again and I think there is almost nothing that would trip up .class code from 1.7 running on 1.6. The trickiest likely issue would be the classloading changes from CLJ-979 but it's hard for me to know for sure without doing a bunch more testing.
I suggested a cljc backport option in 1.6.1, or a tool like cljx which creates cljs and clj files
@ej Friend I think
@danielcompton: any examples?
Friend has plenty of examples, but none integrating with Sente that I’ve seen
Is than an equivalent to *clojure-version*
to get the java version?
@bostonaholic: have you tried (System/getProperty "java.version")
?
@jcf: thanks!
@ej: I've hooked Sente up to Buddy (not Friend but similar). The trick is to store your current user's identity in the session, and look that up when a websocket connection comes in. There's an example of doing auth inside the Sente example app. https://github.com/ptaoussanis/sente/blob/master/example-project/src/example/my_app.cljx
@ej I’ve got some open issues on Sente about alternative auth mechanisms, as session based isn’t what we’re after
@danielcompton: what do you propose?
all i see is this https://github.com/seancorfield/om-sente/blob/master/src/clj/om_sente/server.clj
Allowing the user to pass headers with auth tokens
@ej, I’m using re-frame too
I'm having trouble getting JVM properties to pass through from leiningen. In my project.clj
for a specific profile dev
, I have :jvm-opts ["-Dfoo.bar=abc"]
. I do not see this when running lein ring server
in System/getenv
or System/getProperties
, nor do I see it when running leiningen with -m my.ns
with a -main
in it.
If I do java -Dfoo.bar=abc -cp myjar.jar clojure.main -m foobar.namespace
, it gets picked up.
(defn index
"Handle index page request. Injects session uid if needed."
[req]
{:status 200
:session (if (session-uid req)
(:session req)
(assoc (:session req) :uid (unique-id)))
:body (-> "index.html"
io/resource
slurp)})
(defroutes my-routes
(GET "/" req (index req))
(GET "/chsk" req ((:ring-ajax-get-or-ws-handshake (:sente system)) req))
(POST "/chsk" req ((:ring-ajax-post (:sente system)) req))
;;(POST "/login" req (login! req))
;;
(route/not-found "<h1>Page not found</h1>"))
(def my-ring-handler
(let [ring-defaults-config
(-> site-defaults
(assoc-in [:static :resources] "/")
(assoc-in [:security :anti-forgery] {:read-token (fn [req] (-> req :params :csrf-token))}))]
(ring.middleware.defaults/wrap-defaults my-routes ring-defaults-config)))
Any idea why this returns the raw file? I can’t seem to override the content-header from application/octet-stream
surely the file should be slurped?