This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-22
Channels
- # babashka (36)
- # beginners (42)
- # calva (6)
- # chlorine-clover (25)
- # cider (31)
- # clara (5)
- # clj-kondo (55)
- # cljdoc (3)
- # cljs-dev (7)
- # cljsrn (3)
- # clojure (73)
- # clojure-brasil (6)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (3)
- # clojure-norway (1)
- # clojure-spec (3)
- # clojure-sweden (4)
- # clojure-switzerland (2)
- # clojure-uk (29)
- # clojurescript (93)
- # conjure (21)
- # data-science (14)
- # datomic (19)
- # emacs (4)
- # exercism (3)
- # figwheel-main (38)
- # fulcro (38)
- # graalvm (42)
- # graphql (5)
- # jackdaw (3)
- # jobs (1)
- # joker (2)
- # lambdaisland (1)
- # leiningen (31)
- # malli (8)
- # meander (5)
- # off-topic (27)
- # pathom (2)
- # pedestal (28)
- # re-frame (25)
- # reagent (2)
- # reitit (11)
- # releases (3)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (63)
- # spacemacs (17)
- # sql (1)
Is anyone doing real-time end user analytics with clojure? Eg "your shop has 100 page views" (so not business-wide batch report, but for a user). What are you using to do it? A lot of the high level java things haven't got a lot of people talking with clojure, and I'm hoping to find things like transducer support.
I'm not sure I fully understood your question but I'll try to comment on it. I guess http://metrics-clojure.readthedocs.io could be used for tracking page views(along with any other metrics for analytics). In case you're using Ring - metrics-clojure-ring.
Hello, I'm struggling a bit with the testing of a stateful thing As in the following exemple, it is an alternance of assertions and updates on something stateful. (for remaining as minimal as possible i've materialized my state with an atom but it is more complex in my usecase)
(def state (atom 0))
(deftest one
(is (= @state 0)))
(swap! state inc)
(deftest two
(is (= @state 1)))
How could I write this kind of thing with clojure test ?
Thank you@pbaille You could always put both assertions in a single test with something like
(deftest something
(testing "something"
(let [state (atom 0)]
(is (= @state 0))
(swap! state inc)
(is (= @state 1)))))
@pbaille: also you could take a look at the docs on clojure.test
for composing tests and test-ns-hook
which would allow you to order separate deftest
s — though I rarely see this form used these days.
Is it a bad idea to have .clj and .cljc files for the same namespace? Or is this a common practice? What about .cljs and .cljc?
when you use require
, only the first match for an ns is used, so using cljc requires different namespaces than used by clj and cljs code
one idiom I've seen is having src/clj/foo/bar.clj
and src/cljs/foo/bar.cljs
and then src/cljc/foo/shared/bar.cljc
which both the clj and the cljs file require
thanks!
So far I don’t think it really makes sense…
So I have this library that sets up a bunch of schemas used in multiple internal project. Now, I’d like to include some schemas that involve core.async objects, but I don’t want to force core.async as a dependency for all the services. Is there a good way to only define things if a given namespace/Java class exists?
Oops, seems like I was just confused, and I can do this via e.g.
(when (try (import 'foo) true (catch Exception _ false))
(def MySchema ...))
Onto my next question: is doing this sort of thing a bad idea for any reason?
yeah I thought about separate namespaces, but I think there’s a risk it’ll become unwieldy
I often run migrations and tasks by spawning a temporary docker container and pass it some params. But this time I want to pass it a namespace and resolve the namespace at runtime and run some functions from it. find-ns
doesn’t seem to work when I pass it the name of the namespace in the command line that will be converted to a symbol in the code.
Any idea how I can find-ns
a namespace? Currently it returns nil
@frozenfire1992 find-ns
only returns the ns when the namespace was already loaded:
$ clj
Clojure 1.10.1
user=> (find-ns 'clojure.string)
#object[clojure.lang.Namespace 0x35229f85 "clojure.string"]
user=> (find-ns 'clojure.set)
nil
Oh damn, anyway I can achieve what I am trying to do?
@frozenfire1992 You can also use ((requiring-resolve 'clojure.set/union) #{1 2 3} #{3 4 5})
to force loading the namespace
will try that
That worked @borkdude thanks 🙂
That worked @borkdude thanks 🙂
Any suggestions regarding what lens library would be the best and most reliably maintained in Clojure?
use your own judgment, but IMHO lenses and monads become much less useful without static type checking - you can get pretty far with get-in / update-in
cool, I know nothing about lens implementations because of the above, best of luck :D
I've been using specter as a lens library, https://github.com/redplanetlabs/specter
right, it's a dsl for data updates
i actually don't know enough theory to tell the difference. what is the difference if anyone knows?
Well, lenses are functions which allow get/set kind of operations on nested data structures. Basically you can do stuff like get the value, set the value or apply a transformation on that lens which will effectively update the value where the lens is pointing to
as I understand it specter is designed in terms of queries / modifications across an input, lenses are monadic and designed to be modular and chainable
you can compose specter's queries though
is it just that it's not function composition?
in some ways, I like composition via conj better
(def spec1 [:a])
(def spec2 [:b])
(def spec1+spec2 [spec1 spec2])
so from a theoretical perspective, for something to be a lens, it has to not just be composable, but it must allow composition via function composition?
Spectre is a good suggestion, I'll think a bit about my problem on top of that, thanks about that. Was thinking lenses would be a good solution but spectre should do
@U7RJTCH6J well, I'm not going to go too deep on the actual definition of lenses since that is a bit out of my depth but that is a very important feature of lenses in general
@U7RJTCH6J right - my understanding is that lenses are explicitly functions and follow function composition rules (which is why I compared to -> - which looks like the state monad, and can compose via concatenation of forms, but isn't semantically functions at all)
I'm curious if there's a good example of a task that's easy with a lens library that wouldn't "look similar" with specter
@U7MRZK43B If specter is overkill, you could also look at this one: https://github.com/vvvvalvalval/supdate
@U7MRZK43B Also, there seems to be a lenses lib here: https://cljdoc.org/d/funcool/lentes/1.3.3/doc/user-guide
Spectacles seems to be last updated year ago, Lentes has last commits 6 months ago but build has been failing for months
System.setProperty("file.encoding","UTF-8");
Field charset = Charset.class.getDeclaredField("defaultCharset");
charset.setAccessible(true);
charset.set(null,null);
(System/setProperty "file.encoding" "UTF-8")
(def charset (.getDeclaredField Charset "defaultCharset"))
(.setAccessible charset true)
(.set charset nil nil)
is a first go at itthe interop rules are pretty straightforward https://clojure.org/reference/java_interop
for the specific question - Foo.class
is a java syntax, the equivalent in clojure is Foo
(doto
(.getDeclaredField Charset "defaultCharset")
(.setAccessible true)
(.set nil nil))