This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-04
Channels
- # announcements (5)
- # beginners (56)
- # calva (2)
- # cider (30)
- # circleci (2)
- # cljsrn (90)
- # clojars (3)
- # clojure (18)
- # clojure-dev (9)
- # clojure-europe (3)
- # clojure-greece (14)
- # clojure-ireland (6)
- # clojure-italy (6)
- # clojure-nl (7)
- # clojure-norway (1)
- # clojure-spec (1)
- # clojure-sweden (3)
- # clojure-uk (14)
- # clojurescript (52)
- # cursive (5)
- # data-science (9)
- # datomic (3)
- # emacs (26)
- # expound (11)
- # figwheel (3)
- # figwheel-main (6)
- # fulcro (24)
- # garden (1)
- # graalvm (101)
- # liberator (1)
- # mount (1)
- # off-topic (1)
- # pathom (27)
- # portland-or (2)
- # reagent (13)
- # reitit (2)
- # ring (1)
- # shadow-cljs (10)
- # spacemacs (11)
- # sql (6)
I believe Leiningen doesn't pull in JAR files for dependencies that contain only POMs -- you have to specify the individual dependencies instead -- or use a plugin that pulls them in @pvillegas12
(the plugin I was thinking of is called lein-bom
but it doesn't seem to work with that wss4j project, so perhaps it isn't a Bill-Of-Materials project...? I'm not Maven-savvy enough to understand that stuff)
Are there pros and cons to using get and nth compared to using the data structure itself as a function? For a long while I thought they were the only way to return a not found value, but i just noticed that you can get that behavior with the structures themselves.
({:a :b} :x :y) => :y
One difference is in how get
treats a collection that is nil, e.g.
user=> (def m {:a 1 :b 2})
#'user/m
user=> (m :a)
1
user=> (get m :a)
1
user=> (def m nil)
#'user/m
user=> (m :a)
Execution error (NullPointerException) at user/eval5 (REPL:1).
null
user=> (get m :a)
nil
However, you can use (:a m)
instead of (m :a)
and you'll get the same result as (get m :a)
in a cleaner, imho, way
And keywords and symbols can be called with a default as well.
get
looks better (to my eyes) when used inside a ->
through
Hello, I'm just starting work with clojure. I'm trying to use +`` in the CIDER REPL and getting the error
Unable to resolve symbol: + in this context.``
Hi, I have a question regarding records. Do you send them to your functions as a map or do you send them as parameters? I have like 3 records currently which I want to "Flow" through my functions.
i will use maps, wondering whats idiomatic though š
by records, do you mean things defined by defrecord
or just generally composite data?
I must be doing something obviously wrong, but I can't format a java-time instant:
(jt/format "YYYY/mm/DD" (jt/instant 1555970400000))
Execution error (UnsupportedTemporalTypeException) at java.time.Instant/get (Instant.java:565).
Unsupported field: DayOfWeek
There is an example on the http://Clojure.org website, maybe that will help https://clojure.org/about/jvm_hosted
This stack overflow reply says you need a specify a Time Zone https://stackoverflow.com/questions/25229124/format-instant-to-string
@noisesmith things defined by defrecord. I am using protocols to be able to "Mock" any dependencies to things such as the database.
Right now i just have a :records key in a map where I keep the implementations
a great example of doing this IMHO is stuartsierra/component, which allows the definition of stateful components that can depend on each other with defined startup and shutdown tasks
yeah im using integrant right now @noisesmith š
and that uses exactly what you are describing, a hash map of records that is passed to each one
Hi all, I have a long running process (refreshing a postgres materialised view) that I want to expose via an API route. The idea being that hitting the API route will trigger the process.
Since the process takes a while to complete, I donāt want to wait (and timeout) before giving the API response. I was suggested to use future
solve this & set the process off in a separate thread.
Will this work? Are there any āgotchaās I should be aware of while doing this?
@ben606 there are a few gotchas to using futures - in particular they swallow exceptions and they get thrown later if/when you deref the result of the future
the two simple workarounds are to always eventually consume the result of the future (via deref) that will expose exceptions if any; or to put a try/catch with whatever logging etc. you need inside the future
> always eventually consume the result Is this considered a best practice? In all honesty, what Iām doing feels like a bit of a hack (even if I canāt pin down exactly why).
surely you need the data that the future collected or generated - if you are doing db inserts, you can have a task that consumes the futures as their data is available, and reports any exceptions thrown (or recovers as applicable)
but if you are just doing db inserts from the future itself, you can always use try/catch and do the apropriate logging or recovery in that
but the real problem is ignoring / dropping error conditions - that's no way to run a service :D
Yep! Although in my case, Iām not actually doing the inserts, rather triggering a refresh in the database, so thereās no return value per se. Maybe thatās a hint I should be doing something else
Why are you refreshing the view? if its because the view is "outdated" then it might be possible to make the view reactive. This is part of what the recent drive towards having streaming systems like onyx, flink, spark, etc... is about.
In my experience, the hacky part to updating the a view is that most pre streaming systems dont give you a options to specify when that when, how, why things should be updated.
The reason is actually worse than thatā¦ We have a table in which each row contains the parameters that define a distribution. We want to sample from that distribution regularly. The view simply adds a column with an extra field containing that sampled variable (and some indexing).
but that seems like a sensible approach
there's also executorservice https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html
Is there an obvious (idiot-friendly) reason why I would use executorservice over futures?
the executorservice abstracts the concept of a group of tasks which are related, where you can iterate them all, check their status, etc.
you probably want something like that, and with futures you'd have to reinvent it (and ironically future uses an executorservice under the hood, borrowed from clojure.lang.Agent)
Right. I think that makes sense. Thank you @noisesmith!
@daniel.maksymow it is for metadata
sure thing
Hello everyone, is there a reduce-right in clojure?
none I am aware of
pretty straightforward to write a correct one given what is available, if you aren't worried about optimizing to the utmost.
if i reverse the vector i pass in, wouldn't that suffice?
It depends upon whether the operations you want to do between "pairs" of things is commutative or not.
e.g. if the sequence contains strings, and your goal is to concatenate all of them, the result will come out quite different than a reduce-right
Assuming that by reduce-right you mean what I am guessing you mean.
i was just thinking of it as starting from the last element instead of the first
like in js
thanks anyway andy. made me think about this š
I don't know whether js reduceRight gives the same behavior as reduceLeft on the reverse of the array, or not. Haskell has foldl and foldr, where I am almost certain that foldr is not the same as reversing the list and passing it to foldl.