Fork me on GitHub
#rewrite-clj
<
2020-11-15
>
borkdude15:11:13

@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

lread15:11:39

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.

lread15:11:20

This change made testing under sci easier for me.

borkdude15:11:44

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

borkdude15:11:22

whereas before it kept the line and column metadata

lread15:11:34

Ah… that makes sense.

borkdude15:11:42

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

borkdude15:11:42

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

lread15:11:10

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
borkdude15:11:22

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 ;)

lread15:11:39

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?

borkdude15:11:21

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

lread19:11:51

@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.

borkdude19:11:30

@lee That's quite a document!

lread21:11:46

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

borkdude21:11:32

@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])