This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-27
Channels
- # bangalore-clj (2)
- # beginners (37)
- # boot (16)
- # cider (17)
- # clara (4)
- # cljs-dev (351)
- # cljsrn (16)
- # clojure (219)
- # clojure-belgium (4)
- # clojure-dev (3)
- # clojure-france (2)
- # clojure-italy (24)
- # clojure-russia (23)
- # clojure-spec (55)
- # clojure-switzerland (3)
- # clojure-uk (89)
- # clojurescript (121)
- # cursive (2)
- # datomic (29)
- # devops (2)
- # graphql (8)
- # hoplon (15)
- # immutant (5)
- # lein-figwheel (4)
- # liberator (3)
- # luminus (18)
- # off-topic (9)
- # om (6)
- # onyx (31)
- # pedestal (48)
- # precept (9)
- # re-frame (19)
- # reagent (63)
- # ring-swagger (69)
- # robots (1)
- # slack-help (14)
- # spacemacs (12)
- # sql (2)
- # test-check (4)
- # unrepl (28)
- # untangled (5)
- # yada (3)
Is there a nice way to get specific elements, by index, from a vector, returning a new vector?
(mapv #(get v %) indices)
Thanks
that won't return a vector
oh sorry
I misread that as "map"
good catch!
vectors are functions of their indices
I forgot about that
yes, just have to be careful with index out of bounds with the (mapv v indices)
version. Can filter out nil
s from the get
-based version and not have to worry about exceptions. Unless you want an exception with a bad index, in which case the vector-as-a-function solution works perfectly
Do we have some nice tools for remotely debugging JVMs? I have a Clojure app thats leaking memory
@laujensen i've used yourkit with great success. there is also visualvm which is a lot freer, but i haven't used it
@mccraigmccraig , I’ll check ‘em out, thanks
A quick question: Clojure supports closure where the closure has access to data defined in the parent function.
On the other hand, you can re-assign a new value to an existing variable. And this variable might be visible to the closure.
mahdix: atoms won't race if you use them correctly: that is, if you use swap!
to update their value, and don't have side effects or deref
other mutable containers in the function you pass to swap!
.
Hey! Could anyone recommend me a great Clojure book for someone who is new to the language but mostly familiar with functional programming? I have already read Clojure for the Brave and the True
I purchased Living Clojure and thought it was great. I've also heard good things about The Joy of Clojure, but as a more advanced follow-on book
The Joy of Clojure is advanced, and I’m not sure if you need that much info upfront. I maintain that Programming Clojure by The Pragmatic Bookshelf is by far the best resource available, and written in a style that is true to the language. There is a new 3rd edition coming up, see https://pragprog.com/book/shcloj3/programming-clojure-third-edition.
@U067BPAB1 thank you! How advanced are we talking about here with regard to the Joy of Clojure?
You should have written something in the language already to really benefit from the book.
I wouldn’t rush into it, personally - I’m into my second year doing Clojure commercially after years of FP in Erlang and hobby toying around with Clojure/Scala, and I’ve yet to seriously touch the book. I find that actually writing code is more useful than reading about it - which, admittedly, is much easier to do when you’re paid to do it!
This is also the reason why I like Programming Clojure so much - the book doesn’t faff around and goes straight to the point, all the while (indirectly) teaching you all the good habits required for writing nice, clean, composable Clojure code.
@U067BPAB1 I’ll definitely get myself a copy then! Have you read the ebook? Or is there a way to get a paperback?
I have both the paper and the electronic version of the second edition, which covers version 1.3. Personally I would get the beta ebook for the 3rd edition and just read that, all PragProg books are super easy to read on screen and very well hyperlinked, plus it’s nice to have a bit of color as well.
@U067BPAB1 Ok, thanks a lot for the advice
Np. I also recommend http://4clojure.com if you haven’t come across that already, it’s a good way to learn an idiomatic way of solving isolated problems using the standard library. And above all, try to get a job with it. That’ll boost your understanding much quicker than any book ever can.
@U067BPAB1 I am actually pushing to use clojure on a new project at my current job
Out of curiosity, what has your experience been going from Erlang to Clojure @U067BPAB1 ?
It’s one of those languages (Erlang) that is on my “to learn” list but never quite got around to doing it
Clojure is a much better language. Erlang is more interesting from a concurrency perspective than an FP one, since the FP there is completely incidental (it was deemed necessary to implement the platform) rather than intentional. Both teach you something new, so if you feel like learning something else after Clojure I can recommend it. I enjoyed my time with Erlang but after 4+ years of it I think I’ve exhausted the platform, and I personally don’t think it’s the right fit in 90% of modern distributed/concurrent system development as a lot of the big selling points (failure handling, concurrency etc.) have been implemented outside of the VM these days and I just think that’s the right way to do it instead of having to think about these explicitly within a service.
Joy of Clojure is fun, and from a practical point of view I loved Learning ClojureScript, but that’s about ClojureScript
@U5ZAJ15P0 I’m planning to learn Erlang too. Well, ok, I’ll probably learn Elixir instead, but that’s derived from Erlang.
@U06CM8C3V yes Elixir looks interesting!
hmm, seems that eastwood doesn’t like defrecord forms produced by [org.clojure/clojure “1.9.0-alpha17”]
Hello! Can anyone help me understand the use-case of defrecord? Everytime I write a code, it is usually enough with just a function, but I'm afraid I'm missing the good parts of it!
== Eastwood 0.2.4 Clojure 1.9.0-alpha17 JVM 1.8.0_131
Directories scanned for source files:
src test
== Linting lol.core ==
Entering directory `/private/tmp/lol'
src/lol/core.clj:3:1: suspicious-expression: condp called with 3 args. (condp pred test-expr expr) always returns expr. Perhaps there are misplaced parentheses?
where source is 0% cat src/lol/core.clj
(ns lol.core)
(defrecord Lol [])
When running around 1000 simultaneous clj-http/get requests with :async? true
I get this error:
Exception in thread "async-dispatch-6" Exception in thread "async-dispatch-5" java.lang.OutOfMemoryError: unable to create new native thread
Is there a way to circumvent this?erwinrooijakkers: the correct way to deal with this is to use a queue or channel to line up requests, and then use a fixed number of threads to do the work on that queue or channel. The claypoole library makes it easy to create a pool that works this way and call it the same way you would use futures of pmap normally.
of course you can also increase your max memory usage parameter, but there's still always a limit beyond what your hardware can support, and then you need to control thread creation / usage
@seancorfield : is it public if your team uses GAE or AWS ?
@U3JURM9B6 we use a mixture of traditional data center and AWS at the moment.
(disable-warning
{:linter :suspicious-expression
:for-macro 'clojure.core/defrecord
:reason "Clojure 1.9 defrecord output causes false warning"})
doesn’t seem to workwhat's the proper spelling for a new version of foo-bar
? foo-bar2
or foo-bar-2
?
foo-bar-2
, I think, more strongly implies it was intended to be a distinct symbol with a similar naming scheme, while foo-bar2
is more clearly a mutation of the original foo-bar
and what about foo*
? foo*2
or foo2*
?
again, my preference would be appending the mutation to the original symbol unmodified. so foo*2
this strategy will help you out if you ever need to grep your service for any instances of that function, in any versions that exist
foo-bar'
that's how I've usually done it
read as "foo-bar prime"
and foo-bar''
etc.
for instance, if you did ctrl + f foo-bar*
you would get instances of foo-bar*
and foo-bar*2
obviously @jcromartie is using the same strategy, just with prime ticks instead of numbers
@jcromartie this is specifically re: the new guidelines from rich etc. regarding avoiding breaking changes, which explicitly recommended integers
I haven't seen that
cool, thanks!
I guess the slides in that talk probably indicate an opinion about foo2
vs foo-2
ah ha! the slides have foo-2
which was my preference anyhow
real-foo
😛
@U051H1KL1 and real-real-foo
for the next one?
only then can you go real-real-foo-2
after that its real-foo-final
and that's all the foo
you need
Okay phew
hmm, not actually clojure 1.9 problem https://github.com/jonase/eastwood/blob/eb58d6fb2628e1d178d4b8d2c46d4788b2a20094/cases/testcases/suspicious.clj#L8-L11
is there a spec for the s/describe of a spec ?
I'd love to use spec, but I'm not brave enough to jump onto an alpha version of Clojure itself
@jcromartie we're on alpha 17 in production. High traffic. Large codebase. Heavy use of spec.
Oh? That's reassuring! Thanks.
I might give it a try after all.
FWIW, we’ve been using Clojure Alphas in production since 2011 (1.3 Alpha 7 or 😎. I think we’ve had one “bad” build in all that time (degraded performance). We happened to skip 1.5.0 in production (the only memory leak I can recall) because our release schedule fell in such a way that we went from a solid prerelease of 1.5 directly to 1.5.1.
afaik clojure 1.9 doesn’t muck with many internals in a risky way, too. mostly adding features
stu halloway was in town last week and made a big deal about "alpha" merely meaning "subject to change" and not "low quality" or any of the other associations
yeh I've been using Spec for a couple of projects & its great!
yeah, clojure alphas tend to be quite good (as long as you are willing to rewrite code that uses the new features)
I use get only if the keyword is in a bound name and not a literal
when it's a literal, it's always clear what the keyword is doing
Whereas if it’s in a bound name, it’s ambiguous whether it’s a function, keyword or what-have-you. Gotcha.
eh I use keywords, vectors and maps as functions - because they're all functions
so what if it might seem ambiguous - if it works and you've tested it then it's clear by the fact that they're first in the list that they're supposed to be a fn
@octo221 you should only vectors/maps as functions when they are guaranteed to be non-null (because otherwise you’ll get an npe)
@octo221 my concern is readability and refactorability, I like to use constructs that reduce ambiguity when they are available and they don't impede other development goals
@alexmiller naturally, but then anything could be nil and cause a NPE - that's part of testing & maybe Specing
no, using a keyword as function (or get) will not have that behavior
but using get directly is free, and solves the issue
I don't think it affects readability at all, actually it's more clear sometimes
I strongly disagree
I only ever use keywords like (:foo bar)
when it's exactly like that: a keyword literal and a very simple form
if I want to get a default value I use get
like (get bar :foo :default)
never (:foo bar :default)
It’d certainly be easier to see what (get a-collection unknown-thing)
is doing as opposed to (unknown-thing a-collection)
why is your unknown-thing unknown ?
just ensure it's a keyword
because we aren't using Haskell
no we're using a better language, with a REPL and Spec
Clojure lets you inspect the state of things after you run your code
which is nice
running a compiler (which is a program) to infer what your program would do if run, is no more powerful than simply running your program
@alexmiller out of curiosity: is there a general convention for the naming of clojure
repos in github? I see lots of data
. math
but also some more exotic names, just got me thinking 😄
carocad: there are just a handful of top level “categories” used for contrib libraries - algo, core, data, java, math, test, tools. And then there are other things as well (web sites like clojure-site and clojurescript-site), clojurescript, clojure clr and clr ports
I’ve always found tools
, util
, etc. to be problematic namespaces--everything gets shoved in there. E.g. why does java.util.Date
belong with java.util.LinkedList
?
I’ve been using Java since before LinkedList existed. back then, the JDK was a lot smaller and no one anticipated how Java would grow. at the time, it seemed fine!
Hi I have a problem with ssl in jetty, I implemented https with an issued certificate by a recognized institution however, I am receiving in firefox this message: SSL_ERROR_NO_CYPHER_OVERLAP
@alricu Jetty and Chrome do not have any ciphers in common
https://confluence.atlassian.com/fisheye/configuring-ssl-cipher-suites-for-jetty-414188522.html
@alricu also look here: https://stackoverflow.com/questions/41626616/cant-connect-to-jetty-9-server-via-ssl-with-firefox-50
but it's worth repeating: asking "how do I fix the SSL cipher suite in Jetty" is like asking "what's the best shoe to hammer a nail?"
Put something that's better at SSL in front of your app.
Don't do SSL in your embedded Jetty.
I understand that there are better ways to do that @jcromartie; but in this application i cannot change or implement other things
yes, you want a debugger
with breakpoints
I'd recommend IntelliJ IDEA with Cursive
@alice for your use case I would go for clojure.tools.trace
which allows you to print out everything that is going on in a namespace or for a var
@jcromartie I don't need a debugger, I'm plenty comfy in Emacs, I'm just wondering how dead-simple it'd be possible to make troubleshooting
but you described a debugger with breakpoints
stack traces get you most of the way there
the trick is defining the starting point of tracing executing
well as @richiardiandrea suggested you can trace the fns in a namespace
(trace-ns some.problematic.namespace)
but you have to specify each namespace and/or function that you want to show up in the trace
Cider has trace built-in if I remember correctly so you might not even need to evaluate that at the repl
I would appreciate if someone can guide me on reading data from AVRO file in clojure?
Just use the Java libs
@niten.sagar there are also several clojars https://clojars.org/search?q=avro
re: debugging / finding the source of issues, i find an approach like stu’s here to be the easiest & most widely applicable: http://blog.cognitect.com/blog/2017/6/5/repl-debugging-no-stacktrace-required
Also - an underrated approach is to experiment in the repl, but reify those experiments into unit tests. I wrote a library that makes it easier to take data you have in your repl and inject it into tests https://github.com/noisesmith/poirot
experimenting in the repl helps today, and is great if you are never going to edit or refactor your code, tests are great to have if you think your codebase might ever change
any jdbc experts know why (j/execute! pg ["SET LOCAL app.session_id = 'x'"])
works but (j/execute! pg ["SET LOCAL app.session_id = ?" "x"])
yields a BatchUpdateException “was aborted” with syntax error at the column with the ?
?
the exception message shows the interpolated query, which seems to have the right ‘x’ in it
@noisesmith looks promising! how about publishing it on clojars?
I thought I had
I probably need to add the info to the readme
it's still pretty young, but good enough to be useful, in my experience at least
@a13 I don't think I've pushed the cljs support to clojars yet, but you can get it via lein install
- I haven't used the feature enough to make it feel publishable (I work on clj code a lot more)
Hey I am new to Clojure and I was wondering if you guys could share some of your favorite resources for learning Clojure. I have already checked out Clojure For The Brave And True but I am learning Clojure for the purpose of eventually building React apps with clojurescript and reagent. Thanks!
charlieroth: ClojureScript Unraveled is also good, especially for getting started with ClojureScript if you are an experienced programmer: https://funcool.github.io/clojurescript-unraveled/
i’m late to the using maps and vectors as functions discussion, but i don’t think anyone mentioned polymorphism. e.g. can be handy to have the option of passing a map or a function depending
sure - but the context was implying that it was always being used for lookup
and I'd definitely pass in :foo instead of #(get % :foo)
hmm, yeah maybe not as useful when expecting a map and passing a fn vs expecting a fn and passing a map(?)
@charlieroth check out my earlier message: https://clojurians.slack.com/archives/C03S1KBA2/p1498559140283392
i highly recommend this book by alex miller https://pragprog.com/book/shcloj3/programming-clojure-third-edition
interesting code and examples, good narrative, and pretty comprehensive. It's made for new people. It also isn't scared of java so you'll have a good introduction to the host language if you're unfamiliar
heh, wow, just remembered that ::keys
is new in clojure 1.9 - feels like i’ve been using that forever 😛
@noisesmith this looks interesting. weve been having trouble with data in defs getting too large for tests (yay memory issues), wonder if this could help
@zylox it might help - especially if you load the data locally in the test so that it gets cleaned up when that test exits...
not if the binding vector looks like that, no
but for has some other tricks you can do with the binding vector, even with one coll
+user=> (take 10 (for [x (range) y (range) :while (> x y)] [x y]))
([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3])
what’s the question?
a profiler dump isn’t too helpful w/o the code