This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-20
Channels
- # adventofcode (8)
- # aleph (2)
- # announcements (10)
- # aws (5)
- # aws-lambda (2)
- # babashka (23)
- # beginners (23)
- # biff (9)
- # calva (4)
- # cider (8)
- # clj-kondo (21)
- # clojure (77)
- # clojure-boston (1)
- # clojure-dev (50)
- # clojure-europe (36)
- # clojure-gamedev (3)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-spec (33)
- # clojure-uk (3)
- # clojurescript (22)
- # core-async (3)
- # cursive (10)
- # datahike (18)
- # datalevin (1)
- # datascript (9)
- # deps-new (21)
- # emacs (11)
- # events (1)
- # graphql (11)
- # guix (26)
- # java (7)
- # jobs (3)
- # lsp (12)
- # malli (6)
- # pathom (33)
- # pedestal (3)
- # polylith (15)
- # reagent (5)
- # releases (3)
- # remote-jobs (1)
- # scittle (9)
- # sql (27)
- # tools-build (9)
- # vim (7)
Hi guys. With functions, we can add docstrings like this:
(defn foo
"I add 1 to my argument."
[x]
(+ x 1))
Is it possible to do something like this with multimethods?
(defmulti foo #(do %))
(defmethod foo :bar [x] (baz x))
(defmethod foo :bar
[x]
(baz x))
There's an example of docstrings in the examples part of the docs: https://clojuredocs.org/clojure.core/defmulti#example-561b3b1ae4b0b41dac04c957
Anyway, defmulti
allows an optional docstring after the function name (similar to defn
)
An important thing here: defmulti
allows a docstring, but defmethod
does not.
This is because in general all multimethod implementations are supposed to follow the same interface, they aren't supposed to do radically different things, so if you need to add documentation specific to a particular multimethod implementation that can mean either that the abstraction doesn't fully fit, or that the documentation needs to be implementation comments that aren't important to callers.
Does anyone know of any opensource tooling for translating tempura's edn string files? Something that non programmers could use to enter translations?
Perhaps https://github.com/brightin/pottery helps here
thanks for the tip, pottery would be an alternative to tempura (https://github.com/ptaoussanis/tempura). tempur uses its own edn based format for storing strings, which isn't compatible with gettext / po edit.
I was hoping someone might know of a tempura edn <-> po file converter or something to re-use existing i18n tooling
(case x
0 true
nil false)
> Performance warning, /home/pavlos/Workspace/... - hash collision of some case test constants; if selected, those entries will be tested sequentially
This was unexpected, could someone please explain to me why it's happening? (On Clojure CLI version 1.11.1.1149
)Very interesting, I didn't know that. I should have thought to use hash for debugging 🙂 > I wouldn't use case statements with targets that are heterogeneous datatypes. Yeah, doesn't seem to be a good idea... Thanks!
we have a horrible home rolled thing. Looking for something that will work out of the box w/ whatever debugging dashboards are needed
we use quartz at metabase: https://github.com/metabase/metabase/blob/master/src/metabase/task.clj
lightweight libs, if lightweight works for you: https://github.com/aphyr/tea-time, https://github.com/jarohen/chime, https://github.com/overtone/at-at.
i'm trying to set up quartz on my end and stuff like this
(defn- load-class ^Class [^String class-name]
(Class/forName class-name true (classloader/the-classloader)))
(defrecord ^:private ClassLoadHelper []
org.quartz.spi.ClassLoadHelper
(initialize [_])
(getClassLoader [_]
(classloader/the-classloader))
(loadClass [_ class-name]
(load-class class-name))
(loadClass [_ class-name _]
(load-class class-name)))
(when-not *compile-files*
(System/setProperty "org.quartz.scheduler.classLoadHelper.class" (.getName ClassLoadHelper)))
is what i'm trying to figure outother than quarzite's docs straight up just redirecting to pornography if i don't use the wayback machine, the bootstrapping is the annoying part so this is a great resource
(cron/with-misfire-handling-instruction-fire-and-proceed)
i think it’s configured on the trigger
but i see cron/with-misfire-handling-instruction-do-nothing
, ignore-misfires
, so i would check that namespace and see what in Quartz it is doing, and then check Quartz for how all of that works
I’ve made https://github.com/msolli/proletarian, which we use at work. It’s good if you need persistence and certain guarantees - details in readme.
It’s configurable, so it doesn’t strictly need its own schema. I like to keep its two tables separate from other tables in the application/system. There’s not much to PG schemas - they are essentially namespaces.
https://github.com/nilenso/goose might also be worth a peek, it's a relatively new addition to the space.
Is there a way to make proletarian do a recurring job? Or is that a bit too much hacking
You can have one (or several) workers on every instance. Each worker can have a thread pool with one or many threads. You choose the concurrency levels based on your resources and expected load.
For recurring jobs I do one of two things: 1. Schedule the next job from the current one. 2. Schedule from an external signal like AWS Eventbridge scheduled event.
I think I'm confused about how to program the P in my REPL.
I have a defrecord for something called JenaGraph
which when using the defaults will render its entire contents, which pretty much chokes my REPL buffer.
(defmethod print-method JenaGraph
[x writer]
(.write writer (str "<JenaGraph hash=" (hash x)">")))
When I calll the usual print methods, this works fine:
> (print g)
<JenaGraph hash=-1751499775>
But when I create a new instance of this record, I get the original REPL-choking output. Is there something I can do to direct my REPL to do the short version?you probably need to re-evaluate the print-method implementation to pick up a new record definition
I've restarted a fresh REPL with the new defmethod, and I'm still having this problem.
sounds like the code that defines the record is being loaded twice, with the print-method extension happening between them
Why then does println still have the desired output?
I guess it isn't clear from your description but you say printing stops working "when I create a new instance" so presumably you have an "old instance" and that old instance is maybe created between the two loads
a quick diagnostic you can do is a stick a (println 'A)
above the defrecord, and a (println 'B)
above the defmethod, and then load up a new repl. if you see A printed out twice you having a loading issue, something is causing code to be loaded more than once which can be problematic in many different ways. If you ever see A without a B after it, then you know a print-method was never installed for the most recent definition of the record
if you get B output before you ever get an A output, then you also have something interesting going on(likely also a loading issue, but manifesting in a more interesting way)
So in a fresh REPL, here is the whole output:
About to define JenaGraph
Just defined JenaGraph
About to define print-method for JenaGraph
user> (in-ns 'ont-app.igraph-jena.core)
#namespace[ont-app.igraph-jena.core]
ont-app.igraph-jena.core> (make-jena-graph)
{:model
#object[org.apache.jena.rdf.model.impl.ModelCom 0x1467a240 "<ModelCom {} | >"]}
ont-app.igraph-jena.core> (def g *1)
#'ont-app.igraph-jena.core/g
ont-app.igraph-jena.core> g
{:model
#object[org.apache.jena.rdf.model.impl.ModelCom 0x1467a240 "<ModelCom {} | >"]}
ont-app.igraph-jena.core> (println g)
<JenaGraph hash=112519425>
nil
(prn g)
<JenaGraph hash=112519425>
you have some kind of pretty printer extension thing to make the repl output print nicer and it doesn't print records correctly
So this is something cider or emacs might be doing?
% clj
Clojure 1.11.1
user=> (defrecord F [])
user.F
user=> (prn (->F))
#user.F{}
nil
user=> (require 'clojure.pprint)
nil
user=> (clojure.pprint/pprint (->F))
{}
nil
user=>
You're right, I don't have this problem when I clj --repl
I gotta run now, but you've given me a good direction to investigate. Thanks!
Looks like setting the value (in emacs) of cider-print-fn to nil defers to nrepl.middleware.print/print-fn, for all pretty-printing which looks like it solved the issue for me. https://docs.cider.mx/cider/usage/pretty_printing.html
Is this a good way to vet candidate dependencies if I care about keeping my library/app lean/small?
clj -X:deps tree :project '{:deps {org.jsoup/jsoup {:mvn/version "1.15.2"}}}'
My thoughts:
1. I usually look at deps.edn which doesn't say anything about transitive deps, this seems nicer I think.
2. It will be a bit unforgiving to some libraries because it doesn't take into account common deps but I can live with that (and I could always use :extra
).
and https://github.com/clojure/tools.deps.graph can be helpful if you want a diagram (optionally with lib sizes!)
https://github.com/phronmophobic/snowball is a neat tool, haven't used it a ton
we glance ad-hoc of course but i mean a dashboard, a report, a chart showing release vs size, etc
a nice feature to tools deps would be to list jar sizes, with an option to see transitive deps rolled up on their top level dep or the full tree annotated with size
suggestions and feedback welcome!
@U7RJTCH6J some feedback: that’s outstanding! I was just dreaming of it and there is is for me 🙂
Very nice indeed 🙂