rewrite-clj

2021-11-02T01:37:21.080900Z

okay, got zip/node working!

2021-11-02T01:37:28.081200Z

looking very good, very promising

2021-11-02T01:39:36.083800Z

update: i’m correctly extracting the testing blocks, i’ve converted the testing to deftest and the testing string "does cool thing" to the original deftest’s name plus the string joined as a symbol, using a slugify function i wrote for a different part of the app, so given (deftest fifteen-minutes (testing "works for corp" …, i get back (deftest fifteen-minutes-works-for-corp which is great

2021-11-02T01:41:31.085900Z

next lil snag tho: for some reason, if the last line of the original deftest is a comment, it’ll put the closing parenthesis on a newline (which makes sense) and then no matter how many z/insert-newline-right s i add, it won’t put any newlines between that closing parenthesis and the new deftest :

(deftest fifteen-minutes
    ;; 15 Minutes - check if it works correctly from both sides
  ) (deftest fifteen-minutes-in-corp-score-area
      (do-game
        (new-game {:corp {:hand ["15 Minutes"]}})
        (play-and-score state "15 Minutes")
        (is (= 1 (:agenda-point (get-corp))))
        (is (= 1 (count (:scored (get-corp)))))
        (let [fifm (first (:scored (get-corp)))]
          (is (= 1 (count (:abilities (refresh fifm)))))
          (card-ability state :corp (refresh fifm) 0)
          (is (zero? (:agenda-point (get-corp))))
          (is (zero? (count (:scored (get-corp))))))
        (is (find-card "15 Minutes" (:deck (get-corp))))))

lread 2021-11-02T03:37:45.089100Z

Nice! Comments are considered uninteresting to rewrite-clj. But you can navigate over all nodes via the * functions. See zip API’s left* right* up* down* prev* next* leftmost* rightmost* and also replace* edit* insert-left* insert-right* insert-child* append-child* remove*. Time for sleep for me. Happy to help tomorrow if you are still stuck

😴 2
🎉 2
2021-11-02T14:33:46.091900Z

if I call z/root, how do I turn the result back into a zipper?

2021-11-02T14:34:34.092400Z

I get this error if I write (-> zloc z/root z/down): ClassCastException class rewrite_clj.node.forms.FormsNode cannot be cast to class clojure.lang.IFn (rewrite_clj.node.forms.FormsNode is in unnamed module of loader clojure.lang.DynamicClassLoader @157f289c; clojure.lang.IFn is in unnamed module of loader 'app') clojure.zip/node (zip.clj:67)

lread 2021-11-02T15:20:13.097Z

@nbtheduke, the z/root fn returns the fully realized root node (not a zipper, a node). You can create a new zipper by passing that node into z/edn or z/edn*. Or if you are just looking to navigate to the top of the zipper and continue work you can z/up until you get to the top (z/up at root returns nil). Note that there's an https://github.com/clj-commons/rewrite-clj/issues/149`z/top`.

👍 1
2021-11-02T15:20:49.097800Z

cool, thank you

2021-11-02T15:24:40.100500Z

what’s the reasoning for z/right and others returning nil at the end instead of marking the zloc with :end? or something? i found myself having to write certain logic twice to handle the special case of looking at the final position in a z/subzip when using loop/recur:

(cond
  ;; final position testing branch
  (and final-position?
       (-> zloc z/down testing?)
       (not (-> zloc z/down basic-test?)))
  (-> zloc z/remove* z/root)
  ;; final position all else
  final-position?
  (-> zloc z/root)
  ;; non-final testing branch
  (and (-> zloc z/down testing?)
       (not (-> zloc z/down basic-test?)))
  (recur (-> zloc z/remove*))
  :else
  (recur (-> zloc z/right)))

2021-11-02T15:25:34.100800Z

versus

(cond
  (-> zloc z/end?)
  (-> zloc z/root)
  (and (-> zloc z/down testing?)
       (not (-> zloc z/down basic-test?)))
  (recur (-> zloc z/remove*))
  :else
  (recur (-> zloc z/right)))

borkdude 2021-11-02T15:27:33.101600Z

@nbtheduke That might be because it's closely modelled after clojure.zip and clojure.zip behaves like that too

👍 1
lread 2021-11-02T15:29:01.102600Z

That, and “end” means end of the traversal of the entire zipper (depth-first walk).

lread 2021-11-02T15:30:49.103400Z

Actually end https://github.com/clj-commons/rewrite-clj/issues/155, but I don’t think you need to distract yourself with those nuances right now.

2021-11-02T15:39:29.104Z

excellent, that’s honestly what I’d kind of noticed but didn’t fully understand

2021-11-02T15:39:52.104600Z

i’m writing up the PR for my change now, i’ll post it here so y’all can see the zipper code i wrote with your help!

2021-11-02T15:40:28.105100Z

there’s no easy way to dedent a list , is there? lol

2021-11-02T15:40:40.105500Z

I can use vim to reindent all of the files, but it would be nice to do it programmatically

lread 2021-11-02T16:32:22.108500Z

@nbtheduke, cljfmt, zprint and cljstyle all use rewrite-clj to control indentation (so yup, can be done!) But, might be easier to run your code through one of those as a post-processing step. Or use vim. That said, if you show an example of the unwanted indentation you want to fix we can see what we might do.

👍 1
lread 2021-11-02T19:18:22.110100Z

Cool thanks for sharing!

lread 2021-11-02T19:19:01.110300Z

BTW, did you notice you have some orphaned empty tests like this (deftest runner-basic-actions)?

2021-11-02T19:19:15.110500Z

ha yeah, i’m still not sure how to handle that yet

lread 2021-11-02T19:20:52.110700Z

I guess you could z/remove those empty suckers. But you might want to check if they contain comments that you don’t want to lose first.

2021-11-02T19:23:24.110900Z

Yeah, I’m leaving them in for now while I discuss with my team, but otherwise, I’m very pleased with how it’s worked so far

lread 2021-11-02T19:43:32.111100Z

Awesome!

borkdude 2021-11-02T21:14:17.111300Z

@nbtheduke Awesome job :)

2021-11-02T21:16:11.111600Z

Thank you to both of you!