This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-24
Channels
- # beginners (113)
- # boot (9)
- # cider (6)
- # cljs-dev (33)
- # cljsjs (1)
- # clojure (73)
- # clojure-italy (4)
- # clojure-russia (6)
- # clojure-spec (13)
- # clojure-uk (21)
- # clojured (1)
- # clojurescript (79)
- # core-async (6)
- # core-logic (4)
- # datascript (5)
- # datomic (5)
- # duct (12)
- # events (1)
- # figwheel (9)
- # fulcro (143)
- # garden (2)
- # leiningen (1)
- # luminus (24)
- # off-topic (1)
- # parinfer (7)
- # protorepl (12)
- # re-frame (4)
- # reagent (32)
- # rum (1)
- # shadow-cljs (46)
- # spacemacs (4)
- # specter (27)
- # sql (6)
- # unrepl (3)
- # videos (1)
is there a way to define a cljc macro that: 1. when expanded in clojure, uses clojure.spec.alpha 2. when expanded in cljs, uses cljs.spec.alpha so I have a macro which calls functions from spec, but I need it to use clojure.spec.alpha or cljs.spec.alpha depending on if it's used in clj or cljs
@qqq I would probably use ClojureScript’s ability to alias clojure.*
to cljs.*
and then in my ClojureScript namespace require clojure.spec.alpha
so that it then really requires cljs.spec.alpha
while simultaneously setting up an alias from the former to the latter. This is illustrated in this gist https://gist.github.com/mfikes/3ed89b767048e109891464f1f7e7151b
In other words “pretend” that there really is only a clojure.spec.alpha
namespace and ignore the fact that in one environment it is really named cljs.spec.alpha
. You can also avoid the difference for keywords if you, say use things like ::s/invalid
in your runtime code (it will qualify to the right keyword in Clojure and in ClojureScript.)
hi everyone, i’m looking for a nice solution to a hopefully simple scenario. i have several resources in my app like users, orders etc, and a bunch of crud actions surrounding them. they’re implemented using records. i’d like to be able to define some events for them, for example the 4 crud actions (“order created”, …). for those events, i’d also have to be able to define multiple “listeners” which are called with the event data when one is fired. i’ve looked into several things, using re-frame on the server, tinkering with core.async, but i can’t seem to be able to code something satisfactory up. how is something like this usually implemented? any pointers?
@nicoschneider it's not really clear to me what problem your trying to solve. You could use Kafka, have different types of events on different topics, and expose them on a lacinia-pedestal graphql endpoint for some front-end?
I made a poc running at http://sys3.open-web.nl:8181 like that, using re-frame with re-graph for the front-end.
Kafka is imho comparable to tackling the problem with a bazooka. Sure it's great when it works but managing Kafka cluster is a huge pain; Some MQ is probably what you want instead of general distributed message log system. That said, I don't quite understand either what the problem is that you're trying to solve.
That's why I asked, maybe using transit and send different kinds of maps over websockets is enough
it mostly concerns various events during a plain old ring request handle
while crud-ing the resources i’d like to isolate some sideeffecty things like emails and file writes based on what happens to the “models”
i’m struggling with finding a good architecture for this
@gklijs i would love to, but i can only add websockets as progressive enhancement for modern clients. it’ll run on old machines and/or behind excessive firewalls which apparently block websockets. i already had to go to great lengths to make transit/edn work, i don’t wanna get into the details. in the end, it’ll have to all happen in the ring handler, so i’m looking for a sane concept ^^
i actually tried that, might be that i’m too inexperienced, but for some reason it didn’t switch to long polling on the test devices
i might try that again, but i’d need to change a lot of code to essentially move the events to the client
or rather, have them be fired by the clients
actually, in some cases i’d like them to be private/opaque, which would mean leaving them server-side only anyway
i might’ve misstated my problem … it’s not so much about http or the network, or a server/client communication question, but a software architecture one. i don’t need/have the time, expertise or resources to set up one of those event streaming processes a la kafka etc, where i imagine much of the solution to my problem is moved to the tech stack. i’m just looking for inspiration regarding modelling an easily extensible “event” system, where the events are basically just sideffects like emails or saving an audit trail
e.g. when an order
is created
, call these handlers
You could have something like a rest endpoint, and have the clients call it each minute?
as i said, it’s not about the http communication or having clients send the events
they’re fired after/before something happens to resources that are exposed via http
So what's it about then? Syncing the data available for the consumers on the back end?
no, about the architecture/concept of the events implementation
currently, i have a few extra function calls strewn in the handlers, where needed
what i’d like to be able to do is fire a “generic”, if you want, event, say (events/fire! :shop/order.created order)
that would call the associated listeners
i’m looking for ideas on implementations 🙂
@nicoschneider What about using (add-watch ,,,)
on whatever atom represents your state, (data/diff ,,,)
to see what changed, and then dispatching the event via queues/channels or the like?
@luskwater that’d work for a few things where i have to track individual entities, yeah … i need something “general” as well, regardless of what changed etc. queues would be ideal, i have event handlers which generate files
Sounds interesting: might be interest in a lightweight system for that, but I don’t know of anything myself.
Is there a builtin for:
(defmacro et [& body]
`(try (do ~@body)
(catch Throwable e# nil)))
Initially, this looks bad, as it silently eats the Throwable and returns nil.
However, I often have situations with if
/ cond
, where the test itself may throw an exception (in which case it should "fail")
Is there a builtin for this? Is there a better way to do this? Is the fact I'm using this suggests something else is goign wrong;; swallow exceptions
(defmacro ignoring
[exc & body]
`(try ~@body
(catch ~exc e# nil)))
just wrote that in a projectthanks for this, I swallow exceptions every once in a while, this comes in handy.
I named it swallow
following the spirit of spit
and slurp
go narrower in two ways: only catch the specific exception you might see (or directly prevent it and return nil) and don't wrap a whole body, wrap a specific predicate. If the exception is NPE you can just do #(some-> % (pred?))
I've seen big long term problems caused by someone catching Exception (or even worse Throwable) and returning nil, because they expected NullPointerException - and thus real problems we need to fix are ignored
Hi guys. I'm looking for an idiomatic way to update the value in a segment within a vector. E.g. change [0 0 0 0 0 0]
to [ 0 1 1 1 0 0]
@yogidevbear Specter is your best friend here! 🙂 gimmie a sec and I’ll make an example
Would it make sense to use a combination of something like map-kv
and subvec
?
here's a plain Clojure version:
user=> (reduce-kv (fn [result i v]
(conj result (if (#{1 2 3} i) 1 v)))
[]
v)
[0 1 1 1 0]
Nice work Sundar 👍
user=> (def v [0 0 0 0 0 0])
#'user/v
user=> (setval (srange 1 4) [1 1 1] v)
[0 1 1 1 0 0]
Nice. Thanks @schmee. Is Specter Clojure or ClojureScript or both?
Cool, thanks. I've give that a go
the author answers most of the questions in #specter, so if you run into trouble just ask there 🙂
@schmee @yogidevbear even simpler: (setval [(srange 1 4) ALL] 1 v)
Hi @U173SEFUN. Do you know if there is a similar approach for doing the same thing to a vertical column range within a vector of vectors? e.g.:
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]
to
[[0 0 0 0 0]
[0 0 1 0 0]
[0 0 1 0 0]
[0 0 1 0 0]
[0 0 0 0 0]]
one way is (setval [(srange 1 4) ALL 2] 1 data)
can also abstract it like this:
(defn mat-elems [row col end-row end-col]
(path (srange row (inc end-row)) ALL (srange col (inc end-col)) ALL))
(setval (mat-elems 1 2 3 2) 1 data)
That is really awesome
is there some limit on the number of futures? is it a good idea to have many futures?
@joelsanchez - futures using an expanding pool of threads, but each future monopolizes a real thread
so it's definitely possible to create so many that your app grinds to a near halt
@joelsanchez future's are great when you need to do a one off task in a new thread, but they aren't a good plan if you want to make a large number of threads in parallel - you can look at the claypoole library for that as one good example
anyone have any data on the overhead for keeping data in a set
vs some seq
?
thanks, that confirms my thoughts, I don't really have a need for many futures so I just won't 😛
i suppose my real question is just how things are checked for equality in a set? if i conj #{1 2} 3
will we iterate over the set in linear time?
@alexstokes the main feature of sets is that they are indexed, uniqueness comes pretty cheap once you have that property
checking if an item is in a set is about the same cost as looking up an item in a hash-map
ok great
you wouldn’t know where i should look for that code do you?
just curious how clojure handles it
a simple implementation could just re-use hash-map
and ignore vals
@alexstokes https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentHashSet.java - the set is essentially a balanced tree
thanks!
@alexstokes reading that, you are right! it has a local, "impl" and when you conj an item to a the set, it does (assoc impl x x)
ok cool
that's all implementation details that could change in a future version of course - but the fact that lookups are cheap is an intended feature that will stick around
yeah thats what im after
i was using a seq for some children in a tree but i really want the semantics of set
wanted to make sure i wasn’t gonna do anything silly by using one