This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-26
Channels
- # announcements (9)
- # babashka (98)
- # beginners (52)
- # boot (2)
- # calva (19)
- # cider (58)
- # clj-kondo (4)
- # cljdoc (11)
- # clojure (49)
- # clojure-dev (12)
- # clojure-nl (3)
- # clojure-uk (4)
- # clojurescript (42)
- # core-async (6)
- # cursive (9)
- # data-science (1)
- # fulcro (23)
- # jobs-discuss (2)
- # nrepl (30)
- # off-topic (42)
- # pedestal (6)
- # re-frame (8)
- # reitit (7)
- # remote-jobs (2)
- # shadow-cljs (134)
- # specter (1)
- # vim (13)
Using kondo to clean my project a bit, I get quite a bit of missing else warnings when using if. Is there a more idiomatic way to only conditionally do something?
yes, makes sense, harder to make errors when adding additional statements, since it's an inplicit do. thanks
Stuart Sierra’s opinion piece on this subject: https://stuartsierra.com/2015/06/16/clojure-donts-single-branch-if
@gklijs you can turn the linter off if you disagree with Stuart Sierra: {:linters {:if {:level :off}}}
🙂
yeah, well the fix is ambiguous. you either really forgot something, or you didn't and then you want to use when
I guess types help a bit there: when you forget something in the else branch it's probably not the right type
Well kind of since it's statically types and has the borrow checker. When it sees a certain type, but expects another, it suggest how to get from one to the other. When you use a string inside an enum it suggests to take make it into a reference so the enum will take less space.
Seems like an interesting language. I have listend to a new Rust podcast today: https://twitter.com/borkdude/status/1188064931272364032
Interesting topic, quite similar to my blog, https://www.confluent.io/blog/getting-started-with-rust-and-kafka
I have tried Rust a bit in the past, but I haven't got a really good use case for it. CLIs I can make with Graal now
I still want to try Rust with embedded, but otherwise it was kind of a let down. It takes a lot more time to program, and in some case it's not faster, but even slower than the JVM. Does use a lot less memory but that's hardly a problem. The WASM tooling is great as well. But kind of same story, as long as you don't build games or something cljs will be a lot faster to program.
Hi everyone! How do I include an NPM package in shadow-cljs? Their documentation list special cases, but I just want the simple, vanilla case. Can't figure it out 😞
@thheller that's pretty simple 🙂 in normal CLJS what's the bit that you have to do extra here?
basically everything the webpack guides tell you to do https://clojurescript.org/guides/webpack
wow, that's simple - thanks! And I take care of version bumping like in a normal js project or are thery any gotchas?
you use npm as normal yes, your JS dependencies are kept in package.json
and managed by npm/yarn
perfect, thank you so much!
Hi, I'm trying to use clojure.java-time/interval
but I'm getting an exception "No such var: j/interval"
(require '[java-time :as j])
(j/interval (j/instant 10000) (j/duration 15 :minutes))
Has anyone worked with intervals?(import '(java.util TimerTask Timer))
(let [task (proxy [TimerTask] []
(run [] (println "Hello!")))]
(. (new Timer) (schedule task (long 20))))
I ended up defining some functions to solve this. Maybe there's a lib that already does this for me xD
maybe a question for @U04V70XH6
Java Time has no "interval" (so it's not just the clojure.java-time
wrapper).
See https://github.com/ThreeTen/threeten-extra/issues/2 (by the creator/lead of both Joda Time and Java Time).
Hi folks, what would be the best way to change this:
[
{:name "a" :args [1 2 3]}
{:name "a" :args [5 6 7]}
{:name "b" :args [1]}
]
into this:
{
:name "a" :arg-list [ [1 2 3] [5 6 7]]
:name "b" :arg-list [[1]]
}
I want to take a vector of maps which have a bunch of duplicate :name
values with different vectors of :args
and map the :names
to a vector of vectors of their args.
I'm using Spectre for most of the json transformations, but I'm new to clojure and this transformation is non-obvious to me.(def v [{:name "a" :args [1 2 3]} {:name "a" :args [5 6 7]} {:name "b" :args [1]}])
(reduce (fn [m s] (update m (:name s) #(conj % (:args s)))) {} v)
neato! I'll give it a shot soon! really need to get familiar with the standard library!
I can't seem to get support for stuff like :Doc
using Clojurescript/vim-fireplace. When I try to use it, I get Unable to resolve var: special-doc in this context at line 1 cljs/user.cljs
. Meanwhile, just using clj files, it works fine. Anyone familiar with such a setup?
@alex.sheluchin Maybe ask in #vim ?
I have a question about conventions… when is a bang actually used to declare side-effects? I'm writing a wrapper for interfacing with a socket. When you send something a robot arm is moved (very bangy to me), when I read something it could until there's new input, so also read-response!
? And connect!
? In the end I have bangs everywhere, which doesn't seem right
My approach is to have a function that only does the side effect and name it with !
at the end. Other functions that call this function do not need the bang as they do not directly have side effects.
I like https://stuartsierra.com/2016/01/09/how-to-name-clojure-functions#orgheadline4 >>>Functions which have side-effects are named with verbs describing what they do. Constructor functions with side-effects, such as adding a record to a database, have names starting with create-. (I borrowed this idea from Stuart Halloway’s Datomic tutorials.) Functions which perform side-effects to retrieve some information (e.g. query a web service) have names starting with get-. For words which could be either nouns or verbs, assume noun by default then add words to make verb phrases. E.g. message constructs a new object representing a message, send-message transmits it. I don’t use the exclamation-mark convention (e.g. swap!) much. Different people use it to mean different things (side effect, state change, transaction-unsafe) so the meaning is vague at best. If I do use an exclamation mark, it’s to signal a change to a mutable reference, not other side-effects such as I/O.
Many many people write functions that have side effects with no ! in their names.
IIRC, most of the functions in clojure.core that have ! in their names are: (a) because they are unsafe to use within dosync
transactions (but not all such functions are so marked, by a long shot), and (b) for the mutating functions on transient collections.
For (b), many of those have ! to distinguish them from their immutable counterparts, e.g. conj! vs. conj
👋 Hello! I'm trying to figure out the best way to read in a directory of files into a .cljs
file. I started with a re-frame template and I can read a single file using shadow.resource
as described here: https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745. It feels like I'm going down the wrong path if I want the a directory of files though. Would anyone have any recommendations?
So your input is a directory and the expected output is what exactly? When you say "into a .cljs" file its unclear to me. One interperation could be that you read those files via something like slurp then you just add the text into a file. Maybeing saving it as a var. thhellers solution seems to do that as well as fits into the reloading model. > This works fine and is done quite often all over but common implementations suffer from the problem that the compiler doesn’t know that these other resources were used and won’t invalidate caches properly or trigger re-compiles when those resources were modified.
Good question @U0DJ4T5U1! I'm not sure what the output should be :thinking_face:
This works:
(md->html (rc/inline "./docs/example.md"))
But guess I'd like a vector of all the markdown files in ./docs
.
> One interperation could be that you read those files via something like slurp then you just add the text into a file. Maybeing saving it as a var.
Do you mean that I read the files in with slurp
in a clojure (not clojurescript) file and then referencing the var that contains them in a clojurescript file?