This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-14
Channels
- # adventofcode (62)
- # beginners (78)
- # boot (26)
- # boot-dev (9)
- # cider (73)
- # cljs-dev (33)
- # cljsrn (36)
- # clojure (159)
- # clojure-android (1)
- # clojure-austin (1)
- # clojure-greece (79)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-russia (11)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (107)
- # core-async (22)
- # core-logic (12)
- # cursive (16)
- # datomic (13)
- # devcards (5)
- # duct (36)
- # emacs (4)
- # figwheel (3)
- # fulcro (107)
- # graphql (171)
- # hoplon (27)
- # instaparse (24)
- # jobs-discuss (34)
- # juxt (3)
- # lein-figwheel (1)
- # leiningen (8)
- # lumo (11)
- # off-topic (9)
- # onyx (79)
- # parinfer (1)
- # pedestal (75)
- # re-frame (27)
- # rum (1)
- # shadow-cljs (11)
- # spacemacs (20)
- # specter (17)
- # unrepl (96)
Hi everyone i'm somewhat of a newbie and wondering about database migrations. I have been spoiled with migrations using django which if you aren't familiar are pretty nice. I don't expect there to be as rich an option in clojure but can I get some opinions of some of the options like ragtime/joplin/migratus or other options?
@dfcarpenter I’m a fan of Migratus. The dude that wrote and maintains it, Yogthos, just builds incredibly good stuff. He’s also fairly active on Slack if you ever need any help. It’s the default for the Luminus framework (http://www.luminusweb.net/docs), another one of Yogtho’s creations. It works well. It’s efficient. It’s stable. And most importantly, it’s well documented.
I never got into Joplin or Ragtime because I found and stuck with Migratus via the Luminus template, so I can’t say anything about them.
However, their creators (Juxt for Joplin, Weavejester for Ragtime) are also very reliable, well known, and make great stuff!
Hi I would like to use this as a library locally. Is there any clear information online on how to do it. https://github.com/ghl3/dataframe
Basically want to create the package and then add it as a depenency
hey guys, what is your favorite clojure(script) IDE? I've been playing around mostly with IntelliJ + Cursive and it is quite nice, but heavy. any other things I should check out? One thing i feel like is quite necessary is the IDE doing all the indenting and parenthess/bracket management for you, which feels like it speeds up coding by an order of magnitude
I use VS Code with two plugins: “Clojure” - Andrey Lisin - for repl, autocomplete, docs, and evaluation, and “Parinfer” - shaunlebron - for automatically managing my indentation/closing parens.
@noman I really like atom with these plugins: - proto-repl - let's you evaluate code in your IDE, awesome for interactive development -parainfer: Automatically infer closing parens based on indentation. An essential tool for writing Lisp code. proto-repl allows you to run a repl as a split tab, and loads your entire project, allowing you to access all your methods in all your defined namespaces. Links: https://atom.io/packages/proto-repl https://atom.io/packages/parinfer
have you seen https://shaunlebron.github.io/parinfer/?
I can’t imagine writing clojure without it these day, and it is available for many editors
I've used lein install
but it's not ended up in my local Maven repository. How do I make sure it ends up there and require it as a dependency into my project
Have you tried the lein checkouts stuff? https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies
lein install is the most reliable method - make sure you ar e looking for the right project name and version - checkouts don’t even work without running a proper lein install first
@noman Clojure people are using all kinds of things. Emacs, Vim, Intellij+Cursive, Lighttable, Atom…
nice thing about Clojure is that you can pretty easily do rudimentary support for it into any editor since it’s a Lisp and Lisps are trivial to parse. Also, due to nREPL and socket REPL it’s really easy to integrate all that to a functional REPL and when you have that you already have a pretty good development environment
paredit is easy to implement on top of S-expressions and since everything is so easy to parse it’s not that hard to implement stuff like automatic require inclusion and so forth
I seem to have forgotten how do you get the offending source file, when you get a java.lang.RuntimeException: EOF while reading
without any of your sources showing
Hello everyone, using clojure.data.json pprint to pretty print a json, I'm getting this:
[{"A":
{"B":"0001",
"C":"0002"}},
{"A":
{"B":"0002",
"C":"0002"}}]
when it suppose to indent as this:
[
{
"A":{
"B":"0001",
"C":"0002"
}
},
...
is there any formatting control to turn it into the correct formatting?it’s interesting you say that the first one would be incorrect since I find that much more readable
I know this is a matter of interpretation. First one is correct for clojure, not for json as we see around
that would be more what I would expect to see from a random pretty printed JSON example
but this just proves the point that there is no such thing as “correct” JSON pretty printing
well, you have a point. Even so, I need to print the same output of command jq
which does as you described(I did something wrong on my second example, it suppose to be like yours)
Cheshire has options for controlling pretty printing: https://github.com/dakrone/cheshire#custom-pretty-printing-options
I might be under/over-thinking something. I'd like to make a mount
state that, when started, makes a GET request every five seconds. This works:
(defn get-loop []
(loop []
(future (Thread/sleep 5000)
(-> (http-request-for-blah)
do-something-else)
(recur))))
but I don't know how to write a mount/stop
for this, i.e. kill a looping future. What's the idiomatic way to do a task every period-of-time, and be able to stop that task with another function?@mfm I don’t know if this is considered idiomatic but here’s one way to do it:
(defn get-loop []
(let [running (atom true)
stop-fn (fn [] (reset! running false))]
(future
(loop []
(when @running
(Thread/sleep 1000)
(println "doing stuff")
(recur))))
stop-fn))
(defstate foo
:start (get-loop)
:stop (foo))
FWIW the java.util.concurrent.ScheduledExecutorService
is probably the most efficient and precise way to do this
I am interested, @donaldball! thanks. i'm not familiar with the effect on the JVM of having (future (loop (Thread/sleep ...)))
, so i am also interested in an efficient implementation.
You’re dedicating a thread that’s idle much of the time, and, particularly if your “doing stuff” takes meaningful time, your actual period is going to be longer than stated period. None of this may matter even a little bit for your use case, of course 🙂
stopping single threads from the outside within the jvm is error prone, but future-cancel
uses the most reliable method available - it can cancel paused io or sleeping threads at least
if you care about thread count and overhead of sleeping threads, you could use a go block with async/timeout and launching the side effecting thing in async/thread
waiting on N timeouts only requires the small number of threads core.async allocates on startup (nproc*4+2 iirc)
with something like
(go-loop []
(<! (timeout 5000))
(println "stuff)
(recur))
how do i stop the go-loop?there’s also ScheduledThreadPoolExecutorService which is wrapped by at-at and is meant for periodically running tasks and has a straightforward api for stopping individual tasks
@mfm the usual idiom in core.async is to use a channel that gets closed when you want the loop to exit
also you need to put your stuff (whatever replaces the println) in async/thread if it uses any noticeable execution time (<! (async/thread …))
- because otherwise you can easily starve core.async and halt all async code
so we end up with
(go-loop []
(let [[_ continue?] (alts! [(timeout time) cancel-chan)]
(when-not (= continue? cancel-chan)
(<! (async/thread (do-stuff)))
(recur))))
if cancel-chan is not closed, it does the thing, if cancel chan is closed it returns nil before the timeout completes, and is passed as the channel returned by alts! which is then detected etc.
but returning a future and then calling future-cancel later is fine if you are OK with the overhead of a sleeping thread per recurring thing
future-cancel will stop things that sleep
you can leave the <! off of the async/thread call if blowing up in that call shouldn’t stop the loop and you don’t want to add execution time to the timeout time (but consider what happens if you repeatedly do the call and it throws exceptions every time, or if the call does something that accidentally takes longer than the timeout time leading to snowballing resource usage)
core.async makes async easier but parallelism and async are intrinsically complex
here’s a situation i’m in, and some code i’ve written - is there a better way to express this?
and i’ve just got this straightforward reduce:
(reduce (fn [grid [[x y] value]]
(assoc-in grid [x y] value))
grid
move)
is that reduce the best way of expressing this, or is there some obvious better / more natural way that’s eluding me?
that reduce looks fine to me - you don’t need to destructure [x y] btw - you could change it to [grid [coords value] (assoc-in grid coords value)
you could change that function definition to (partial apply assoc-in)
(reduce (partial apply assoc-in) grid move)
looks great to me 😄
i’ve somehow temporarily bricked my intellij since asking the question, but once i get things working again i’ll try that out and i’m sure it’ll be perfect - thanks again! 🙂