This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-22
Channels
- # announcements (16)
- # babashka (7)
- # babashka-sci-dev (14)
- # beginners (34)
- # calva (80)
- # clj-kondo (23)
- # cljdoc (17)
- # cljs-dev (1)
- # cljsrn (10)
- # clojure (51)
- # clojure-berlin (3)
- # clojure-europe (14)
- # clojure-italy (10)
- # clojure-nl (2)
- # clojure-norway (211)
- # clojure-uk (5)
- # clojurescript (4)
- # cursive (22)
- # datalevin (12)
- # datomic (2)
- # defnpodcast (1)
- # duct (5)
- # emacs (4)
- # events (2)
- # fulcro (3)
- # graalvm (1)
- # interop (3)
- # introduce-yourself (4)
- # java (1)
- # jobs (7)
- # kaocha (38)
- # leiningen (3)
- # lsp (11)
- # malli (4)
- # membrane (5)
- # music (1)
- # off-topic (28)
- # pathom (13)
- # pedestal (3)
- # polylith (4)
- # portal (10)
- # practicalli (1)
- # re-frame (33)
- # reitit (2)
- # remote-jobs (1)
- # sci (6)
- # shadow-cljs (49)
- # sql (4)
- # xtdb (3)
Before I go stare at decompiled code for a while, how well do primitive functions compose? I have a function which returns a primitive function, and I want to compose a bunch of them, but the composition will also need to take this into account, otherwise the argument will be boxed back
As long as the compiler knows that these are primitives coming in/out, that should work
But it may depend on the exact scenario
I can verify it doesn't Given
(defn primf [^long x ^long y] (fn [^long z] ,,,))
(reduce (fn [f' f] (fn [^long x] (or (f x) (f' x)))) (map (fn [[x y]] (primf x y)) pairs-of-longs))
x
is boxed before being passed around to f
in the reducing function, 😞higher order functions are always boxed
loop/recur (or macros that produce one like areduce etc) are really the only way to stay with primitives for something like this
After all, functions are just objects, and who am I to deny their nature? :thinking_face:
I have a thing that may be relevant https://gist.github.com/hiredman/d6ea3e30be757fef6da6
There already exists "Rich Already Answered That!". Maybe there should be "Kevin Already Made a Gist on That!". :D
There's a thesis for a reflective tower of interpreters as a compiler for clojure just waiting to be written
What's a good way to add a docstring to a defmethod
, aside from a comment in the line below the defmethod
?
I could do the same, of course it doesn't show up when calling (doc foo)
:thinking_face:
hint ) look at arglists of defmulti
:arglists '([name docstring? attr-map? dispatch-fn & options])
so you can add docstring placing a string right after the name
@U04V4KLKC yes but that's for defmulti, not defmethod
my bad, sorry )
so you are looking for a way to add a "comment" to defmethod? asking because docstring make sence only attached to var
and for multimethod the var is the one declared via defmulti. defmethod is for mutating it.
Yes, since defmethod
doesn't make a new var, there's nothing to attach the docstring to.
But you can make that var yourself and attach the docstring to that:
(defmulti f identity)
(defn f-x
"f-x does f on x"
[x]
...)
(defmethod f :x [x] (f-x x))
But unless you really need a docstring for some reason (docs generation, code discovery, automatic tests, whatever else), I'd stick to a plain comment.@U2FRKM4TW you can achieve the same via
scratch that ) I was wrong(defmethod f :x "f-x does f on x" [x] ...)
It is actually a feature 🙂 After all, when calling a multi-method, you should regard it as just a method and don’t depend on implementation details such as the individual method implementations.
With a deps.edn
setup, is there a configuration to have the repl automatically load a namespace in every file (just like the user ns)?
not really what you're asking but related: (apply require clojure.main/repl-requires)
(notice nothing is quoted) - this will put all the usual stuff that you get in the initial ns (pprint, doc, source, javadoc, etc.) into the current ns
not really built-in, but you can customize your repl any way you like doing something like https://insideclojure.org/2020/02/11/custom-repl/
interesting, running a require before evaluating every repl input
That looks like just what I need @U064X3EF3, but I’ve been trying to put it into my deps file under :aliases :dev
without success (using cider), seems like perhaps cider’s connection overwrites the :main-opts
(?)
hard for me to guess how it might interact with cider or what those aliases do
The aliases just add :extra-paths
and cider’s connection string looks like this:
/opt/homebrew/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"} refactor-nrepl/refactor-nrepl {:mvn/version "3.4.1"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}}' -Mdev:test:cider/nrepl
so it adds it’s own :main-opts
main opts cannot concatenate. CIDER needs nrepl’s main to start the nrepl server. But nrepl doesn’t play nice with subrepls clojure.main repls anyways so it won’t work after solving the main opts problem
highlighting:
:aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]
not sure if it is directly related to this but each evaluation in nrepl calls clojure.main/repl
for the form sent: https://github.com/nrepl/nrepl/blob/master/src/clojure/nrepl/middleware/interruptible_eval.clj#L84
I see @U11BV7MTK. Is there a way to solve the main problem in cider, i.e. autoloading a certain ns
everywhere?
what is fqn
?
fully qualified name
personally, I find this kind of stuff to be too much magic for me to remember - if I want something, I just require it
Your probably right. Thanks for the responses.
for a while I had a dev
function in my user ns, so I could call (user/dev)
to do all the requires/ refers in the current ns, but nowadays I just require as needed (including frequent usage of (apply require clojure.main/repl-requires)
)
i have the apply require clojure.main/repl-requires bound to C-c h and it evaluates that snippet. makes each namespace an IDE 🙂
Great ideas, thanks!
I’m running into a File name too long
error when using clojure.core.match/match
with a large number of clauses. I assume I’m hitting https://clojure.atlassian.net/browse/CLJ-1852. Is there any workaround for this?