This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-28
Channels
- # announcements (11)
- # aws (30)
- # beginners (98)
- # calva (11)
- # cider (42)
- # clj-kondo (4)
- # cljdoc (1)
- # cljsrn (5)
- # clojure (132)
- # clojure-europe (4)
- # clojure-ireland (1)
- # clojure-italy (35)
- # clojure-japan (2)
- # clojure-nl (5)
- # clojure-spec (5)
- # clojure-uk (24)
- # clojurescript (71)
- # clojutre (1)
- # core-async (6)
- # cursive (9)
- # data-science (4)
- # datascript (3)
- # datomic (78)
- # duct (16)
- # emacs (14)
- # events (2)
- # fulcro (141)
- # graalvm (5)
- # hoplon (14)
- # hyperfiddle (2)
- # jobs-discuss (14)
- # joker (8)
- # luminus (2)
- # off-topic (7)
- # om (1)
- # pathom (4)
- # pedestal (7)
- # planck (2)
- # quil (1)
- # re-frame (14)
- # reagent (2)
- # reitit (14)
- # robots (1)
- # shadow-cljs (20)
- # spacemacs (25)
- # specter (1)
- # sql (122)
- # tools-deps (63)
- # unrepl (2)
- # yada (34)
I'm trying to figure out the max number of days in the current month...
but I keep getting org.joda.time.DateTime cannot be cast to java.lang.Character
@sova share your code...?
@sova Not familiar with joda time, but in clojure.java-time
(if you have the luxury of java 8+):
(require '[java-time :as t])
(let [today (t/local-date)
leap (.isLeapYear today)]
(.. today getMonth (length leap)))
How can I get two completely different jar built from the same project? I have my main program that is currently build, and in the same project/repo I'd like to have a secondary program that is not built when the main jar is built, but can be build on the side
I have one project, and two profiles in it, but I would like one of the profiles to consider only a subset of the sources (e.g. myproject.entrypointB and myproject.stuffrelated.toB)
Maybe a clearer example of what I want to do is that I have a dependency that is fairly heavy (600Mb+) and I'd like to make it optional at build time, by not building some classes and including the dependencies in the uberjar unless explicitly required
I don't think it tackles my problem, it more separate one project into a few smaller projects
@mfm I think it was some discussion on forum about maintainable code, and one discussed, that having to maintain code, where there is one global state, and all the app works on it is like antipattern of globals in any language...
very well. if somebody made a specific claim in their book like, “clojurescript single state atoms are a bad way to maintain state” i’d hear them out. otherwise i don’t know what to do with “atoms are bad”. i mean, your postgres database is global and mutable.
While using Clojure Tools Deps I'm getting following error. How can I resolve it?
Hi there! I'm looking for some tutorials to get started. Ideally it would be a tutorial to build a web app (maybe with database?) in clojure/clojurescript or both. Is there anything you would strongly suggest?
Have a look at "Clojure for Brave and True".
For ClojureScript there's book "ClojureScript Unraveled".
Check out this recent thread https://clojurians.slack.com/archives/C053AK3F9/p1558591282377500
Not sure what your looking for exactly but open-bank-mark does fit the description https://github.com/openweb-nl/open-bank-mark but it may be to much.
@U26FJ5FDM any chance you commented on the wrong thread? hehe interesting project though, I may try to read it to learn more.
is there any list with online resources for practical Clojure learning like 4Clojure, project Euler, http://exercism.io? what would you recommend?
How to start using ClojureScript? You setup a Leiningen project and add some dependencies and then do lein build and it generates JS code or else? Are there any good tutorials on that?
Also I couldn't find any information on how to manipulate DOM (i.e. use ClojureScript for traditional JS tasks) on the official site
@sy_borg Project Euler is not Clojure-specific. I don't know of any such list. But you can add http://codewars.com and http://codesignal.com to it - you can solve programming katas in Clojure in browser there.
In terms of software design, what are your thoughts on using a single map as function input as well as function output (at least in non-trivial functions) instead of positional arguments? e.g. 1
(defn combine [top-section mid-section bottom-section] ...)
(combine top-section mid-section bottom-section)
would become
(defn combine [{:keys [top-section mid-section bottom-section]}] ...)
(combine {:top-section top-section :mid-section mid-section :bottom-section bottom-section}
e.g. 2 Given (def summary {:title "This is a title" :body "This is the summary body"})
(defn render [title body] ...)
(render (:title summary) (:body summary))
would become
(defn render [{:keys [title body] :as summary}] ...)
(render summary)
EDIT: Or rather, what is the clojure way?Is that meant as a good or a bad thing? 😛
I believe eliminating unnecessary entanglement in the form of argument order if you have, let's say, more than 3 parameters is a good thing. But I'm a newbie.
I very definitely prefer a map--avoids bugs from getting something in the wrong spot, and it’s very powerful, especially when used in connection with destructuring.
I seeee... I've had a sliiight disagreement about it at work (I'm for eliminating positional arguments whenever possible) but the first example does look ugly indeed, so I'm not sure.
One small gotcha is the potential for bugs due to typos in map keys, but :man-shrugging:
which one looks ugly? The destructured one?
building the literal map on the spot
(combine {:top-section top-section :mid-section mid-section :bottom-section bottom-section}
vs
(combine top-section mid-section bottom-section)
gosh, do you want to remember what you're doing 6 months down the road?
What are you referring to?
Write it like this:
(just in general, not a jab at any code, friends)
I definitely prefer open maps, preferably with namespaced keys these days
i'd love to see some examples of maps vs sequential arguments. it'd hammer home some good design principles. like don't rely on sequence when you don't have to
(combine {:top-section top-section
:mid-section mid-section
:bottom-section bottom-section})
Sure, that's definitely cleaner, but still I don't think there's a way to get rid of that repetition 😞
what does combine do?
Heh, I have a keyboard shortcut in my IDE — I type ==<tab>
, and then just “foo” and it types :foo foo
for me.
I’m assuming the combine
is just an arbitrary example.
It's repetition for the viewer though! (minor point, sure, but nonetheless it's practically junk) yeah, combine is arbitrary, doesn't really matter what it does (it does nothing) 🙂
Yeah, it’s a bit repetitive when it happens. Usually the value isn’t quite exactly the same as the key in practice, e.g.
(combine {:top-section (get-top-section)
:mid-section (get-mid-section)
:bottom-section (get-bottom-section})
yeah - especially if you have namespaced keys already that you're passing through - you might e.g. then just select-keys
from some other source
most of the time when I have the key and the value exactly the same is when I’m debugging:
(cljs.pprint/pprint {:id id
:username username
:role role})
and that’s kind of throwaway code anyway.
I think that’s very readable
it's a different philosophy than C/++ making a little DNA transcriber that can run real fast down the data...
keyword args might be a nice compromise indeed :thinking_face:
I vaguely remember reading that there was something problematic about keyword args. I’ve never used them myself. Do they play nicely with Clojure spec for example?
Or just the first {
if you’ve got an IDE/editor that automatically inserts the closing }
You may have seen in the #clojure channel, but I’ll repeat it here for completeness: the disadvantage of keyword params is they get in the way when you try to compose 2 fns, and the inner fn takes keyword params.
If I have a map, say {:foo 1: bar 2}
and I desctucture like so (let [{:keys [foo bar]} map] (+ foo bar))
, is there a way to destructure, but also rename at the same time?, i.e., something like (let [{:keys [a :as wibble b :as wobble]} map] (+ wibble wobble))
?
@dharrigan in the same line? you can add another line to your (let [..])
statement (let [foo wibble, bar wobble])
it's unfortunate that destructuring using keys
with namespaced keywords, loses the namespace
what would you do with a namespaced local?
afaik there's no way to create a namespaced local binding
my mental model is that a namespace is a property that belongs to some named object (symbol, keyword), with a local binding you don't have a reified container, just a name for a scoped value
Is there a way to create a “default profile” for the clj
cli? Such that whenever I run clj
, certain deps are always merged in?
You can also ask in #tools-deps for more targeted audience
Ah, thanks.
I'm not sure what the solution is, but I know the problem is:
(let [{:keys [foo/thing bar/thing]} big-ball-of-things]
(println thing))
I can't think of a clean syntax for that, and namespaced locals seem like a really weird feature. you are of course free to use {thing1 :foo/thing thing2 :bar/thing}
you can either do what was suggested (manually rename) or just use the fully-qualified names
What project structure do you guys prefer? Having all the routes for a web-app under a namespace called routes
or to structure your app according to the different "parts" i.e project.payments.routes
instead of project.routes.payments
This can be expanded even more but i hope you get the point.
I am a bit burnt from an old monolith I worked on in C#, 300 controller-classes under the "Controller" namespace 🙂.
maybe there were even more..
module.*
is a modern approach, and can benefit you in the case for a transition to a micro-services architecture
routes under routes
. I just checked to see where I got that idea and it looks like that is how it is done in Sotnikov's Web Development with Clojure book.