This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-22
Channels
- # adventofcode (78)
- # announcements (12)
- # babashka (2)
- # beginners (116)
- # calva (20)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (51)
- # clojure (32)
- # clojure-android (1)
- # clojure-dev (4)
- # clojure-europe (91)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-spec (12)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (9)
- # conjure (3)
- # cryogen (4)
- # cursive (4)
- # data-science (1)
- # datomic (5)
- # depstar (5)
- # fulcro (39)
- # google-cloud (2)
- # kaocha (2)
- # malli (7)
- # off-topic (3)
- # pathom (3)
- # pedestal (5)
- # re-frame (19)
- # rewrite-clj (54)
- # ring (3)
- # shadow-cljs (12)
- # spacemacs (12)
- # specter (3)
- # tools-deps (63)
Dumb request: Should rewrite-cljc move to line/col to mirror Clojure's own metadata rather than row/col?
Are you talking about with postional support enabled? https://github.com/lread/rewrite-cljc-playground/blob/master/doc/01-introduction.adoc#tracking-position-with-the-zip-api
I'm not using the zip api, so I mean for this: (node.proto/form-meta (rewrite.parser/parse-string "(assoc {} :k 10)"))
No idea, I'm sticking to the node.protocols api though so I don't hit uncharted territory.
@borkdude it is new and might be going away… It was part of support for eliding positional metadata from readers. I might just hardcode the eliding instead. Breaking change but should not affect anyone.
> This metadata is not in the original source, and therefore assumed to be uninteresting to users of rewrite-cljc. Huh, the metadata is one of the critical parts I started using rewrite-clj in the first place ;)
But I see the point of wanting to elide the location metadata when writing forms including metadata
So @dominicm, some things might not make perfect sense, but if they have been around in rewrite-clj for a long while, we won’t change them in rewrite-cljc to avoid breaking compat with rewrite-clj.
Yeah @borkdude, I hit the problem in one place in Clojure, for quoted list:
(meta '(1 2 3))
{:line 1, :column 8}
And in many more with sci (which I think you might have since addressed).I can’t even remember where I put eliding of metadata in rewrite-cljc, but have it on my todo to review.
This problem shows itself in rewrite-cljc on coercion from Clojure forrms to rewrite-cljc nodes.
Which happens automatically in many places.
So if I wanted to add a node via '(1 2 3)
this would get coerced to to a rewrite-cljc metadata node without the eliding.
@dominicm that said, if you find stuff that is really irksome we might consider supporting through options, or in more extreme cases, breaking changes.
My todo list is long, but will listen if it is really bothering folks after the first official alpha release.
Is there anyway to know that a token node is a symbol, rather than ##Inf or something else special? (not sure what token nodes pick up)
@dominicm I have some of these helper functions in clj-kondo's code:
(defn symbol-token? [node]
(symbol? (:value node)))
@borkdude But that's not part of the protocol! :P I suppose it can be specific to the token node interface though, yeah
but if you try to sexpr
a map node with an uneven number of children, you're asking for it
also it's less performant to sexpr composite things when you can just look at some key
(defn boolean-token? [node]
(boolean? (:value node)))
(defn char-token? [node]
(char? (:value node)))
(defn string-from-token [node]
(when-let [lines (:lines node)]
(str/join "\n" lines)))
(defn number-token? [node]
(number? (:value node)))
(defn symbol-token? [node]
(symbol? (:value node)))
(defn symbol-from-token [node]
(when-let [?sym (:value node)]
(when (symbol? ?sym)
?sym)))
the :token
tag isn't very informative. one option is to add an extra field but this is one of those things that should have been in it since the beginning maybe
yeah, I think adding the predicates is the way to go. I have added a node-type
on my branch, but it is internal and to support testing. And it doesn’t answer the abstract question that a caller would be asking.
a function that returned some keyword could also be handy if you want to dispatch on something:
(defn tag+ [node] (if (symbol? (:value node)) :symbol) ...)
(case (tag+ node) :symbol ...)
Hmm… interesting. If you have ideas and an interest, feel free to add them to: https://github.com/lread/rewrite-cljc-playground/issues/5