This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-29
Channels
- # announcements (1)
- # babashka (15)
- # beginners (37)
- # calva (94)
- # cider (3)
- # clj-kondo (17)
- # cljsrn (2)
- # clojure (45)
- # clojure-europe (39)
- # clojure-germany (1)
- # clojure-norway (2)
- # clojurescript (16)
- # component (18)
- # conjure (1)
- # cursive (13)
- # datalevin (3)
- # datomic (12)
- # docker (2)
- # duct (5)
- # eastwood (2)
- # emacs (4)
- # events (8)
- # fulcro (8)
- # inf-clojure (5)
- # kaocha (8)
- # lsp (24)
- # malli (11)
- # meander (3)
- # off-topic (19)
- # polylith (11)
- # remote-jobs (4)
- # sci (61)
- # shadow-cljs (9)
- # spacemacs (34)
- # sql (10)
- # tools-deps (27)
- # xtdb (10)
? Spacemacs + clj-refactor problems ?
Some documentation says that installing the clojure layer in Spacemacs automatically loads clj-refactor, but none of the cljr-blahblah functions show up in Meta-X. Then I read I should do (clojure :variables clojure-enable-clj-refactor t))
in the layer spec, but that sends Spacemacs into death-recovery mode. Then I tried installing the clj-refactor package in the Spacemacs place dotspacemacs-additional-packages
and doing
(require 'clj-refactor)
(defun my-clojure-mode-hook ()
(clj-refactor-mode 1)
(yas-minor-mode 1)
(cljr-add-keybindings-with-prefix "C-c C-m")
)
(add-hook 'clojure-mode-hook #'my-clojure-mode-hook)
and various permutations of that in dotspacemacs/user-config
, but still none of the cljr-blahblah functions show up.
any clues for me?Perhaps #spacemacs and/or #cider might be a better venue for this? You're more likely to get specific help there than in a general channel.
Deleting the original now you've posted elsewhere (so no one duplicates effort). Good luck resolving it!
Replied in #spacemacs
Is it okay to have a cljc file sharing the same namespace as a clj file? And if so, how to I access the variables defined in the cljc file from the clj file?
I'm not sure you can do that, but even if you could, I'm not sure that it's a good idea. Why not just move all the clj code into the cljc file or use two separate namespace names?
no, you can't do this - the platforms load (only) the platform specific file or if not found, the cljc file
@U6SEJ4ZUH keep in mind that you can put clj-specific, or cljs-specific, things in a cljc file using reader conditionals
Are there any resources/guides on how to incorporate testing a library's public API for breaking changes into a project's test suite? I'd like to automate the process of enforcing the https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/Spec_ulation.md constraints on an external API as I refactor a project so I don't accidentally impose a breaking change on myself.
i've just uncovered an interesting issue in our codebase around some tagged-literals seemingly violating the principle of least surprise
we have been returning defrecord
objects from a custom tagged-literal reader, and having those defrecord
objects participate in a protocol - it's all been working just fine until i ran across this issue
someone had put a tagged literal into a def (which seemed like a reasonable thing to do at first blush):
(def foo #ctx/event-path [:blah])
which was ok... until c.t.n.r/refresh
was called, after which point everything broke
it turns out that the defrecord
object foo
had a stale class (presumably because tagged-literal induced dependencies are not recognised by tools.namespace
, and namespaces were therefore recompiled out of order), and so no longer participated in the protocol
should tools.namespace
be able to recognise tagged-literal induced dependencies ? or is that a step too far for it ?
tagged literals are just tagged literals - they are only tied to classes via some context where reader fns are supplied
in foo
, would it make sense to call the record constructor instead there? that would make an explicit reference to the implementation
yeah, i have a data_readers.cljc
it wouldn't make sense to call the record constructor, because the objects are part of a serializable pure-data definition... i can stop using records+protocols though and just use plain maps and multimethods
or maps with protocols with :extend-via-metadata true
oh, nice idea!
@UEENNMX0T that works very nicely
i'm now adding the :extend-via-metadata
protocol method implementations to a defrecord
object - so there are initially two available routes to protocol method satisfaction for the object
after c.t.n.r/refresh
the class-based protocol methods become stale, but the :extend-via-metadata
implementations of the protocol methods are declared with namespaced symbols, so remain current, and the objects continue to work with the protocol
and, since the print-method
extensions declared for the stale defrecord
class continue to work, i still get the full deserialise/reserialise roundtrips for the tagged-literals
awesome!
huh! that's very clever hah
lol, well that turned into some of the trickiest code ever... but i finally have a tagged-literal which works on both clj and cljs, has a full de/serialize roundtrip, and does not surprise with c.t.n.r/refresh
Ayyyy nicely done!
I think you'd still potentially have the same issue of dependency tracking (but maybe it wouldn't actually break due to the class differences)
I'm not sure whether it would make sense to change tools.namespace in this way, but would welcome an issue at https://ask.clojure.org so we can make a tns jira out of it
https://ask.clojure.org/index.php/11845/tools-namespace-does-recognise-deps-implied-datareaders
I am thinking, what if clojure.lang.LongRange
/`clojure.lang.Range` implemented clojure.lang.Reversible
? I guess the only complication would be in the infinite case. In the finite case, the reverse range could be computed in O(1) space/time with some integer arithmetic.
Motivation: this
(rseq (range (count xs))
is IMO much clearer than
(range (dec (count xs)) -1 -1)
Hi folks. Just to confirm, is there a better method of getting the str representation of a var other than these options?
Example:
The var is #'foo/bar
Expectation: “foo/bar”
method 1)
(str (subs (str my-var) 2))
method 2)
(let [var-meta (meta my-var)] (str (:ns var-meta) "/" (:name var-meta)))
if i have a function reference user$square
, can I turn that into a var?
yeah i know that user$square
is a class name but that's what's printed in the error message i'm getting. i'm doing some shenanigans with alter-var-root
in a function that accepts a function and i was hoping to do it with a plain function instead of a macro
user=> (defn square [x] (* x x))
#'user/square
user=> (class square)
user$square
user=> (resolve (apply symbol (clojure.string/split "user$square" #"\$")))
#'user/square
(only works for simple functions in simple namespaces -- there are probably a lot of edge cases to handle for the general case)
lol i know we're all nerd sniped but i don't need y'all to spend a bunch of time on this
That's probably safer than my hack, yes:
user=> (resolve (symbol (clojure.main/demunge (.getName (class square)))))
#'user/square
I always forget about it, since it's in clojure.main
which I rarely look at!