This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-03
Channels
- # aws (27)
- # beginners (64)
- # boot (14)
- # calva (10)
- # cider (36)
- # cljs-dev (13)
- # cljsrn (79)
- # clojure (58)
- # clojure-berlin (8)
- # clojure-france (1)
- # clojure-italy (18)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (28)
- # clojure-uk (29)
- # clojurescript (55)
- # core-async (20)
- # cursive (5)
- # datomic (105)
- # emacs (17)
- # figwheel-main (13)
- # fulcro (20)
- # graphql (4)
- # hoplon (1)
- # hyperfiddle (2)
- # jobs (7)
- # jobs-discuss (110)
- # off-topic (23)
- # pathom (1)
- # perun (2)
- # re-frame (87)
- # reitit (2)
- # shadow-cljs (8)
- # spacemacs (2)
- # tools-deps (118)
- # vim (11)
Hello, all! I have a couple of queries that I have been pondering on for a while:
* Is there an idiomatic way to design error handling for a project? Say, specifically, for a web project? Currently, I am using failjure
, and while it is nice for small snippets, I find that I am now tied to using it everywhere, and readability is also taking a hit due to the main logic being hidden within the failjure code itself. What cleaner ways are there to approach error-handling in general in Clojure?
* What would be some nice open source projects to read to get a good sense of best practices in Clojure (libraries, backend code, etc).
* Any good (and updated) resources on learning ClojureScript? I have the book from Packtpub, and it seems promising enough, but the very first chapter jumps into using a bunch of different (and wildly varying) ways of just setting up a ClojureScript project. That appears to be kind of overwhelming. Also, figwheel
seems to have a newer avatar (figwheel-main), but most people still seem to be using the old figwheel. Use figwheel
or go with figwheel main
?
My two cents here @UDV3M0U10, as far as error handling goes, is that monads aren't usually considered idiomatic in clojure. My recommendation, if you're writing a web service would be to validate incoming data (using spec or schema) and handle external errors (using exceptions) at the edges of your system. This would push both out of your business logic, and give you more confidence that the meat of your code is just on the happy path. If errors are more a part of your domain, I'd go with a monadic approach. For learning clojurescript, http://clojurescriptmadeeasy.com is probably the best blog on clojurescript in particular, though it's a bit sparse. Learning cljs is a weird process, since you need to know javascript, including idiosyncrasies of your host (node/browser), as well as clojure. For actually using clojurescript, I've settled on shadow-cljs, which has some rough edges, but is pretty full-featured and is a bit less magical than lein-cljsbuild for example.
Also http://cljs.github.io is a good cljs reference.
Also, for ClojureScript, yes, I agree - finding resources that are cohesive seems to be rather difficult! I will check out the resource that you mention. Cheers, and thank you for your help again.
Is there a straightforward way to get a lazy sequence of lines from a sequence of filenames? I tried line-seq
inside with-open
but didn't work because I needed to realize the line sequence before with-open
closed the reader. I want to do processing on a set of files as if they were all catted together in one big file.
@U7KD4HQ1W Are you doing the processing outside the with-open
block?
Yes. With one file it's easy to do it inside; with multiple files I ideally want to get a line sequence without having to store all the lines/intermediates
problem is the with-open
will close it before anything happens. you need to keep all those files open simultaneously if youre using line-seq
. how big are your files? i'd suggest reading them all into memory if small enough
In practice they are not too big, so assembling them in memory works. I was just wondering if there was a neater solution to the problem. (usually there is with clojure!) Thanks for your help.
@U7KD4HQ1W Something ugly i hacked together, does the stuff lazily but isnt that clean. might help:
(defn lazy-cat'
[colls]
(lazy-seq
(if (seq colls)
(concat (first colls) (lazy-cat' (next colls))))))
(let [readers (->> ["file1"
"file2"]
(map ))
lines (->> readers
(map line-seq)
(lazy-cat'))]
(do-your-stuff-here lines)
(run! #(.close %) readers))
as you can see the closing has to be done manually š
š Thanks! Makes sense (I think, will have to look at it a bit longer)
hey, I can't figure out easy way how to clean up all my namespaces. After some refactoring, I can't run tests, coz some functions which where moved to different namespaces are now colliding with where they where, so I would like to have "clean sheet" after refactoring, so unload and reload all the namespaces
My solution to a large scale refactor like that would generally be to kill/restart the test runner or exit/restart the repl
It's just not worth the time to try and get everything cleaned up properly vs the time it takes to exit/restart
another question I feel I am missing some idiomatic approach I see pattern emerging in my code... I have top level functions called by REST layer, which all take in two ids, find the objects by those ids and call some function This "some function" is the only distinctive specifics, but getting ids, and translating them from ids to objects (maps) is common for all those kind of function... how to abstract or shorten it coz all of my functions have the same shape (same args, which are transformed)
Hello all, how do I convert this new double[][] { { 30 }, { 20 }, { 50 } }
to clojure?
Do you mean like this: [[30] [20] [50]]
[[30.] [20.] [50.]]
to keep desired double type
could you show the line that throws this error?
(let [dataset (DefaultXYZDataset.)]
(.addSeries dataset "USA" [[30.] [20.] [50.]])
(.addSeries dataset "CHINA" [[30.] [20.] [50.]]))
ah cool @lennart.buit
yeah, I am checking whether it actually works tho :ā)
because it appears to be an array of Objects, whereas we want an array of primitives
yeah, this is an array of boxed values, whereas you want an array of primitives
https://stackoverflow.com/questions/38352003/clojure-define-2d-primitives-arrays-like-double
Is (shutdown-agents)
the only way for a clojure app to exit when using futures? Or is there some way to shutdown futures individually?
shutdown-agents
is the best way. there is future-cancel
but that wonāt necessarily do anything useful (depends what the future task is)
future-cancel is my favorite Clojure docstring btw: āCancels the future, if possible.ā
apocalyptic ā¦. or, not?
My futures don't need to be canceled. They reach the ready state as expected. Was just wondering if there was a non-global way to clean up the future in a way that would allow the main thread to exit. Thanks for the confirmation.
Like others, Iām about to try clojurescript again for the new year; intimidated by the infrastructure advances since I last tried and since my books-on-hand were written. Iāve got a [card] game Iāve written in JS with Vue.js. Iām feeling like shadow-cljs + reagent is considered a good way to go?
That's pretty much where I've landed for my various projects. Definitely still some rough edges with shadow, but it's got all the features I care about, including npm integration and lots of build targets.
nice. If I get it cloned (it currently is one page, in browser, no server) - I might try to add some firebase integration.
As far as I know, figwheel is browser oriented, and may be more solid than shadow-cljs, but I needed to compile the same code to node, which I don't think figwheel does.
Figwheel can work with node, and it can also work outside of Lein (there is figwheel-main)
@U04VDQDDY how does it compare with shadow-cljs? I never really got started with figwheel except for a small browser app a few years ago because of the above assumptions.
I know shadow-cljs has a hot-reloading mechanism, but I've never used it, so I can't compare
It's pretty good, if a little buggy on the skinny branches (for example, when running tests using a custom main function it loses track of which tests exist). Does figwheel handle stuff like production builds, dependencies, bundle optimization, and integration with npm? Or is it still just the hot-reloading part?
I am trying to understand the connections between namespaces and file names and directory structure. (Any good articles on the topic would be appreciated.) Iāve been looking at examples in the clojure namespaces and have a question about one in particular. The namespace clojure.spec.alpha is contained in the directory/file path āspec.alpha/src/main/clojure/clojure/spec/alpha.cljā and there is also āspec/gen/alpha.cljā and āspec/test/alpha.cljā. My question is what will this structure look like when alpha (or alpha2) is done and the namespace becomes just āclojure.specā?
and which paths become classpath roots is up to whatever tooling is building your classpath
https://github.com/clojure/spec.alpha/blob/master/pom.xml#L101 is setting up the classpath root for building spec.alpha