This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-01
Channels
- # announcements (3)
- # beginners (59)
- # calva (23)
- # cider (58)
- # clojure (125)
- # clojure-dev (18)
- # clojure-dusseldorf (1)
- # clojure-europe (21)
- # clojure-germany (1)
- # clojure-hamburg (1)
- # clojure-italy (13)
- # clojure-nl (29)
- # clojure-poland (3)
- # clojure-spec (61)
- # clojure-uk (74)
- # clojurescript (12)
- # core-async (6)
- # cursive (4)
- # data-science (7)
- # datomic (14)
- # defnpodcast (1)
- # events (4)
- # fulcro (72)
- # juxt (36)
- # kaocha (3)
- # nginx (3)
- # off-topic (14)
- # pathom (5)
- # ring-swagger (68)
- # shadow-cljs (25)
- # spacemacs (8)
- # sql (42)
- # tools-deps (8)
- # vim (6)
Does future-cancel
do anything other than signal an interruption to that future's thread?
not really, no
it's going through an executor so there's some task mgmt over the top of that
I see. I have a component that works in a background thread, and I was looking for a better way to implement a synchronous shutdown. This is the way I did it:
(defrecord ActionProcessor [event-queue
action-queue
execution-repository
stop-handle]
component/Lifecycle
(start [this]
(let [should-stop? (atom false)
stop-promise (promise)
stop-handle #(do (reset! should-stop? true) @stop-promise)]
(future
(loop []
(when-let [action (q/take action-queue 1000)]
(when-not (= :timeout action)
(try
(dispatch action event-queue execution-repository)
(catch Exception ex
(.printStackTrace ex)))))
(if @should-stop?
(deliver stop-promise true)
(recur))))
(assoc this :stop-handle stop-handle)))
(stop [this]
(stop-handle)
(assoc this :stop-handle false)))
I have a feeling that there is a better way to do this
@seancorfield What are some namespaces/functions you like from 1.10.1, that are currently under development?
@j3elam There's almost nothing new in 1.10.1 compared to 1.10 (except bug fixes) but in 1.10, the interesting new stuff is clojure.datafy
(in terms of new namespaces).
can someone enlighten me what are the behavior differences between deftype and defrecord?
https://lispcast.com/deftype-vs-defrecord/ https://clojure.org/reference/datatypes
Another good pithy explanation I've seen is :
- defrecord
is for information
- deftype
is for mechanism
Can someone suggest a cleaner way to write stuff like this ? I want to use the "->" threading macro but the asserts get in the way.
Hey guys, I just downloaded clojure via the installer for windows (it downloaded as powershell module). I need help getting it started.
Tried and failed to get Clojure working on Windows, sorry @inagbotamuno;[
#Jephthah There is a channel #clj-on-windows that probably has the highest density of Clojure users on Windows on Slack.
@inagbotamuno I dont use windows but this seems to be an alternative way: https://lispcast.com/clojure-windows-8/
Much appreaciated @rahul080327 😄
@sylvain I don’t know if this is the best way to do it but the first thing I thought of was “nil-punning” by using if-let
or when-let
rather than ->
. You would have to rewrite your functions to return either some value or nil
depending on if they pass the test though.
Right but the nice thing about doto in this case is that it conveniently returns the threaded value because assert returns nil.
yes, very useful for side-effects
(doto println)
inside ->
is a popular debugging trick
also if you find yourself always calling (assert)
on a function's return value, try taking a look at postconditions
And beware that it throws AssertionError which may be surprising if you only catch Exception in your top-level logging handler
Hi everybody, I’m a newcomer to the Cojure world and want to give it a try for the frontend part of my app (with ClojureScript). I’ve played around a bit and I know most of the theory basics, but still not feeling comfortable about designing an app, structuring code, working with libraries and other stuff you get with practice. So, what resources are typically recommended to newcomers for clojurescript development? Books, tutorials, screencasts, etc. - I’ve found a few but some of them seems outdated, so it’s hard to follow, and others have little to none reviews… Also, not just for clojurescript, but for clojure - are there any “must-read” resources?
thanks @a.pittendrigh I was looking at reagent and re-frame choosing what to try out, will start with reagent then 🙂
any way to redef a a local binding defined by a let inside a function using with-redefs
or similar?
use case is: i'm trying to write a quick-ish running integration test around a function that retries multiple times, and fails. in production, it retries a bunch of times with exponential backoff, in test, i want it to try fewer times with less backoff
binding
?
i've never used binding
before, it looks like as of clojure 1.3 it's intended for dynamic, top-level-bound vars
you can use with-local-vars, or refactor so you don't need to alter the locals
let bindings aren't vars - there's no var to redef
cool thanks. considering i'm working from a test namespace, i don't even know how to refer to the let-bound binding. namespace/function.local-binding
?
there's intentionally no access without relying on fragile impelmentation details
the common refactor is an optional map supplying override parameters, and an arity overload that supplies the default values
so (defn frob ([x] (frob x {:timeout 1000})) ([x opts] (let [{:keys [timout]} opts] ...))
in your test you provide the opts map, in normal code it shouldn't be needed
you can even use this to mock out implementation details or side effects in tests
also you usually want to merge opts on top of the default in the full arity version, rather than only providing if the opts map is absent
so (def defaults {:timeout 1000})
(defn frob ([x] (frob x {})) ([x options] (let [opts (merge defaults options) {:keys [timout]} opts ...] ...))
I wonder if there's a doc / blog for that pattern somewhere, I see it so often with top level code that does IO and needs unit testing