rewrite-clj

https://github.com/clj-commons/rewrite-clj
borkdude 2020-11-15T15:35:13.061700Z

@lee I made a metadata-related change to sci. This might help with the metadata-related issue you had a while ago when testing rewrite-clj with sci

lread 2020-11-15T15:40:39.064Z

Oh cool, thanks @borkdude, I will have a look soon! I just recently finished a change that, by default, elides reader generated location metadata on coercion from form to rewrite-cljc meta node. I had it also cover sci’s :end-line and :end-column.

borkdude 2020-11-15T15:41:16.064500Z

kewl :)

lread 2020-11-15T15:41:20.064600Z

This change made testing under sci easier for me.

borkdude 2020-11-15T15:41:44.065100Z

yeah, right now if the user does (with-meta ... {:foo 1}) in sci, ... will only contain {:foo 1} as metadata, nothing else

borkdude 2020-11-15T15:42:22.066Z

whereas before it kept the line and column metadata

lread 2020-11-15T15:42:34.066300Z

Ah… that makes sense.

borkdude 2020-11-15T15:42:42.066600Z

this had to do with a security option, but now changed the implementation for that

borkdude 2020-11-15T15:43:42.067600Z

I ran into this when I wanted to expose grasp to a CLI which also uses sci to parse code ... it's a bit meta, but this resulted in wrong line information in the output

lread 2020-11-15T15:46:10.069400Z

Cool, I’m just about to start updating my rewrite-cljc design notes on namespaced things… I’ll ping back for your input after done!

👍 1
borkdude 2020-11-15T15:52:22.070100Z

Detail:

$ cat /tmp/fn_literal.clj
(require '[clojure.pprint :as pprint]
         '[clojure.spec.alpha :as s]
         '[clojure.string :as str]
         '[grasp.api :as g])

(s/def ::spec (fn [x]
                (and (seq? x)
                     (= 'fn* (first x))
                     (> (count (second x)) 1)
                     (some-> x meta :source (str/starts-with? "#(")))))

(let [matches (g/grasp g/*path* ::spec {:source true})
      rows (map (fn [match]
                  (let [m (meta match)]
                    {:source (:source m)
                    :match match
                    :url (:url m)
                    :line (:line m)}))
                matches)]
  (pprint/print-table
   [:url :line :source :match]
   rows))
$ script/run-cli - /tmp/fn_literal.clj <<< "#(foo %1 %2)"

|  :url | :line |      :source |                    :match |
|-------+-------+--------------+---------------------------|
| stdin |     1 | #(foo %1 %2) | (fn* [%1 %2] (foo %1 %2)) |
This would output line 14 before because the local match had line number 14 ;)

lread 2020-11-15T15:58:39.071200Z

Ha, that’s funny, I spent a good while the other day staring https://github.com/borkdude/sci/blob/4d8d05096975a66be312ba2162d04fc53ca6b761/src/sci/impl/interpreter.cljc#L611. I guess it is unused now?

borkdude 2020-11-15T15:59:21.071700Z

yeah, it's unused, I just forgot to remove it. Will do now

borkdude 2020-11-15T16:00:02.071900Z

done

👍 1
lread 2020-11-15T19:43:51.075400Z

@borkdude, I made an initial pass through my https://github.com/lread/rewrite-cljc-playground/blob/lread-ns-kw-map/doc/design/01-merging-rewrite-clj-and-rewrite-cljs.adoc#-namespaced-maps-and-keywords---in-progress for rewrite-cljc. I expect they will benefit from additional pass with a refreshed Lee-brain tomorrow. I’ll ping you again after I’ve done that. Note that GitHub does not do a great job of rendering my adoc here… so you might want to try an alternate viewer.

borkdude 2020-11-15T19:51:30.076100Z

@lee That's quite a document!

lread 2020-11-15T21:00:46.077400Z

@borkdude Hah! Hopefully the namespaced elements section is not too long to digest. I shall try to slim it down further later tomorrow.

borkdude 2020-11-15T21:07:32.080400Z

@lee This section right? https://github.com/lread/rewrite-cljc-playground/blob/lread-ns-kw-map/doc/design/01-merging-rewrite-clj-and-rewrite-cljs.adoc#node-creation My initial reaction: It feels more natural to me to have (map-node children) and (map-node children opts) I like it when args don't shift position when you have a +1 arity. I'm not too fond of the {:type :literal} approach. I think auto-resolved is the appropriate term for it. When it's not auto-resolved, it doesn't refer to a namespace alias. So I would go with opts being {:auto-resolved true/false :prefix "..."} and store these as simple fields (not maps) in the defrecord type:

(defrecord MapNode [children prefix auto-resolved])