This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-30
Channels
- # adventofcode (18)
- # beginners (27)
- # boot (5)
- # cider (3)
- # cljs-dev (2)
- # cljsrn (1)
- # clojure (78)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-uk (1)
- # clojurescript (11)
- # css (1)
- # cursive (11)
- # data-science (6)
- # datascript (3)
- # datomic (3)
- # emacs (24)
- # graphql (1)
- # hoplon (2)
- # off-topic (1)
- # om (8)
- # onyx (1)
- # portkey (11)
- # re-frame (18)
- # ring (5)
- # ring-swagger (1)
- # shadow-cljs (1)
- # sql (5)
- # testing (1)
FWIW, git has some affordance for ignoring whitespace changesโsee the -b
and -w
options to git diff
, for example. (GitHub and GitLab have the same feature in diff view, although it's not always obvious how to toggle it.) That's not meant to disagree about alignment though.
"Note: there is no support for inline value specification, by design." https://clojuredocs.org/clojure.spec/keys
wondering if someone has a cool keys
drop-in that supports them
(I agree with the spec
principles btw... but sometimes I just know what I'm doing ;))
Not excessively hard to implement... syntax would be :req [int? ::foo ::bar ::baz]
where int?
means a predicate for the following keyword, :foo
. Similar to metadata syntax (note that kws aren't IMetas)
will give it a shot someday
One day we'll all use fully AST aware editors and argument / binding alignment will be a UI option ๐
has anyone used refs and STMs in production code? Iโm struggling to sea use case where it is favorable to use over one big atom
If it's possible to partition the problem you're trying to solve into several effect scopes (say several queues such that most STM is only between two of N queues), the STM tools Clojure includes can be useful and meaningfully reduce contention between multiple threads.
In general they tend to be rarely used especially in library code because that's a super application-specific property which requires global knowledge of your system and its state update behavior to leverage.
It's also easier (makes fewer fragile assumptions) to structure your application as a bunch of computation followed by a big-bang swap!
using some comparatively cheap state merging function.
@rymndhng FWIW, we have 75,000 lines of Clojure and only a small number of atoms and a few agents. We have no refs. I think that out in the real world, STM is rarely used -- but can be very valuable in the (very) few edge cases where it is actually appropriate. So, yeah, what @arrdem said ๐
actually, I can't think of a single situation where I have seem STM used; most concurrency problems seems solvable via: build new data structure, do a pointer swap at the last moment
i.e., atom
s, yes.
(or agent
s)
I wonder if the rise of core.async headed off a lot of what refs might have otherwise been used for?
probably; though for me, it's mostly http://curtclifton.net/papers/MoseleyMarks06a.pdf
I think @dominicm meant that it would be better to have STM in cljs than in clojure ๐
I have a question, if I have a project based on clj cli, how can I build a jar from that?
I wondered if I needed to collect up the classpath, and add each one to the fat jar.
https://dzone.com/articles/java-8-how-to-create-executable-fatjar-without-ide This might be my answer, or at least in abstract form.
@dominicm I think you could trace what Leiningen does, my first guess would be to figure out how to get the list of jars and copy their contents into a new zip/jar https://github.com/technomancy/leiningen/blob/master/src/leiningen/uberjar.clj
That's what I've started to look at @U06QSF3BK. It's all quite roundabout, I'm surprised there's no library to go from classpath->jar.
Yes, and there are a lot of options on that route. In portkey (https://github.com/portkey-cloud/portkey) Cristophe Grand did a tree-shaker that packages the minimum needed deps starting from a var :)
thinking that such a deployment package creation from inside the repl could be quite awesome (like push the thing into AWS/Lambda, or into a container)
@U06QSF3BK if this is something of interest to you, I've just got a jar that contains clojure & a helloworld.clj built, and I don't think it will be difficult to hook in tools.deps.alpha to this system.
hmm ok, so I have a java.util.Iterable<Map<String, Object>> representing a huge file and I know i can treat this as a clojure seq, and I have done so succesfully, for example by using take
and processing the item.
https://dzone.com/articles/java-8-how-to-create-executable-fatjar-without-ide This might be my answer, or at least in abstract form.
Hello All! I have a very frustrating problem, because it should be obvious, but I cannot pass. How can i set a scheduler (exactly hara.scheduler) to a smaller period than 1 second. "/1 " means 1 second, but "/0.5 " doesn't work. Even if i set the "truncate" parameter to :millisecond, cannot use milliseconds. The documentation also silent about the topic. Do not I understand the capabilities of a scheduler? O.o Happy New Year to our glorious Community!
@mindenaaron if you want to run something subsecond it may make sense to look into https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newScheduledThreadPool-int- and then scheduleAtFixedRate
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html
I can also use core.async, but i really wanted to use a real clojure scheduler, but cannot understand why I am not able to schedule something with milliseconds. Thanks anyway. ๐
At first I just want to execute a function periodically, it is a few lines with core.async.
@mindenaaron thereโs this wrapper over the Java executor service stuff too https://github.com/overtone/at-at
Yes, there are several clojure scheduler. i did my research and choosed hara.scheduler
re STM, it depends of the application type. most of us write server-side web backends, STM is almost inherently unsuitable for that (b/c you want servers to scale horizontally, and STM is per-server) but that
assume I have the following data structure:
[{:delim ["โโ" :F]} {:align \โ} {:delim [:F "โโฌโ"]} {:align \โ} {:delim ["โโฌโ"]} {:align \โ} {:delim ["โโ"]}]
what would be the most idiomatic / concise way of counting the number of :F
s? I do a:
(count (keep (comp #(some #{:F} %) :delim) data-structure))
now, but I have the distinct feeling Iโm missing some more direct routeand nathan, I assume specter can do this more succinctly but Iโm trying to avoid dependencies in this particular scenario
@mbjarland it's trivial with #specter
(count (select (walker #{:F}) data))
(walker afn)
will recursively "walk" in your data, search by something that satisfies afn
.
walker
is a "navigator", then you need to say "what to do with this data"
In this case, I use select
, that just return a list of "what navigator find".
But you can use (setval navigator :new-value data)
to REPLACE "what navigator find", for example.
@mbjarland best way with specter is (count (select [ALL :delim ALL (pred= :F)] data))
walker
is not appropriate for this use case, as it traverses parts of the data structure you don't care about (which reduces performance and can cause bugs)
he explicitely said he's not looking for a specter solution, I'd say what he has is not bad in pure clojure
the highest performance way with specter is something like (transduce (map (constantly 1)) + (traverse [ALL :delim ALL (pred= :F)] data))
, which doesn't materialize any intermediate data structure
@bronsa if I see bad specter guidance, gotta correct it ;)
@bronsa @nathanmarz and @souenzzo thank you. If I end up pulling in specter I know what to do now. Indidentally:
(count (select [ALL :delim ALL (pred= :F)] data))
is not that much terser (not at all in fact, though arguably easier to grok) than my original pure-clojure:
(count (keep (comp #(some #{:F} %) :delim) data))
so I guess Iโll consider the clojure version decent (as a side note, the fact that you can use specter as a reference point for terseness I think speaks to the beauty of specter)
is there an official clojure grammar somewhere? somethng detailed enough to write an actual production clojure parser from it ?
EDN is close, but there are differences
tools.reader is a Clojure implementation of a reader that can read Clojure source code. Many tools that analyze Clojure source code use it.
It isn't a grammar, but an implementation in code of a reader. Unlike the one in clojure.core (implemented in Java), it is implemented in Clojure. Not sure if that makes it any more useful for your purposes.
Yeah. I've written a bunch of clojure-like grammars and own most of the git-blame for the clojure.g4 you'll find around. Don't go down that road unless you have a good reason to, tools.reader and the ecosystem around it (rewrite-clj etc.) is very good.
Just a side note: The most official docs for Clojure syntax on http://clojure.org do not allow symbols that the Clojure reader allows in symbols. For example, on this page: https://clojure.org/reference/reader you will find no mention that the character '=' is allowed in symbols, but it is allowed by the implementation. Clojure is in many ways defined by its implementation, not some English spec.
Yup. To the point that there's some reader behavior such as :
being legal inside of keywords that Alex has said is unintended but won't be removed for compatibility.
clojure.g4 ?
There's an antlr-grammars repo around which contains what purport to be grammars for a variety of languages and data formats. I did a bunch of work on the clojure grammar in that repo at one point.
I found it via a quick Google search after asking: https://github.com/antlr/grammars-v4
the parser for my Ox language is written in antlr4 using a derivative of the clojure.g4 grammar and I know https://github.com/venantius/glow uses an unattributed copy of clojure.g4 as well.