This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-13
Channels
- # announcements (1)
- # babashka (12)
- # beginners (10)
- # biff (9)
- # calva (2)
- # cherry (21)
- # cider (14)
- # clj-commons (76)
- # clj-kondo (8)
- # clj-on-windows (34)
- # cljs-dev (5)
- # clojure (48)
- # clojure-austin (7)
- # clojure-europe (97)
- # clojure-nl (1)
- # clojure-norway (14)
- # clojure-uk (22)
- # clojurescript (137)
- # conjure (33)
- # cursive (4)
- # datalevin (1)
- # deps-new (4)
- # devcards (2)
- # duct (3)
- # events (1)
- # fulcro (12)
- # graphql (9)
- # hyperfiddle (16)
- # jobs (8)
- # kaocha (1)
- # leiningen (6)
- # lsp (39)
- # malli (38)
- # membrane (20)
- # nbb (68)
- # observability (7)
- # off-topic (49)
- # pathom (11)
- # polylith (8)
- # portal (22)
- # re-frame (6)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (24)
- # spacemacs (2)
- # squint (6)
- # xtdb (7)
Is there a way to use defn with intern
? or any other way to get a doc string in there and have the IDE show the function signature?
Example:
(create-ns 'foo)
(intern 'foo (defn bar "docs" [] "baz"))
That breaks and I wasnt exactly shocked.
(create-ns 'foo)
(intern 'foo 'bar ^{:doc "docs"} (fn [] "baz"))
This successfully makes the function but the docstring doesnt work and my IDE wont show the signature.
Any thoughts?did you read the intern
doc string?
"The var will adopt any metadata from the name symbol."
(intern 'foo (with-meta 'bar {:doc "docs"}) (fn [] "baz"))
for nrepl based IDEs this will work as they query the runtime for docs. For static based tooling this will not work (Cursive, clojure-lsp)
If this is for a macro or something, normally I just switch ns call defn and switch back
Ya, so I don't remember perfectly, but what I've done in the past is something like:
(let [previous-ns *ns*]
(ns foo)
(defn bar []
"Some doc"
:baz)
(in-ns previous-ns))
I think maybe you need to wrap *ns*
with ns-name or something. But this is the gist of it.
I have an issue, worded in ๐งต
(->> rows
(mapv (fn [row]
(let [columns (atom {})
entry (into {}
(map-indexed (fn [i x]
(let [k (-> headers
(nth i)
keyword)]
(swap! columns assoc k (index->column i))
(println [k (index->column i)])
[k, x])))
row)]
(with-meta entry {:my/columns @columns})))))
what could be going on? as mentioned the keys are distinct so each assoc
call is not overwriting the prior entries
row
has 32 items. I verified again that all printed keys are different (32 different keys exactly)
hmmm, the original code that didn't completely work was using transient/persistent!. now with atoms it works as intended
the transient docs https://clojure.org/reference/transients grep for "bash in place"
sadly the docstring didn't hint so. I can't keep the ref guide in my head for arbitrarily long
I also specifically don't like that it the uses !
convention but it pretends to be pure. Seems an odd hybrid. :)
> like, the contract is you have to use the return value I'll see if I can add this as an Eastwood rule, it has it easy to declare "don't use x as a side-effect"
> easiest thing is to just not use transients ever yeah never was a fan but I was dragged into them lately.
but if the transient usage is outside of clojure.core best to assume it has this bug unless proven correct, people refuse to read the docs on transients and just say "hey, mutable collections!"
someone implement the transient java interface on top of redis, ignoring the contract and the possibility of calling persistent! and it made the frontpage of http://lobste.rs
first rule of transients club is to write an algo with ordinary persistent data structures, then sprinkle transients only at the end
Feel free to check out this test case, I think that's it, but you might be able to come up with some extra nuance https://github.com/jonase/eastwood/pull/442/files#diff-e26378bf60c68079448d682ee1e4918b16dd7f2e8e989c474de436cde11b176f
If you want mutable collections, use mutable collections like Java.util.HashMap. If you want to speed up some updates to persistent collections in a local context, you can make them transient temporarily, the nice thing is they follow the same pattern as their persistent counterpart so you don't need to change your code one bit. That's why you have to use their return. They're designed to be used like persistent collections so it's easy to go from persistent -> transient with minimal code change. That's an awesome feature in my opinion.