Fork me on GitHub
Noah Bogart01:11:21

okay, got zip/node working!

Noah Bogart01:11:28

looking very good, very promising

Noah Bogart01:11:36

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

Noah Bogart01:11:31

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


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
Noah Bogart14:11:46

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

Noah Bogart14:11:34

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') (zip.clj:67)


@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`z/top`.

👍 1
Noah Bogart15:11:49

cool, thank you

Noah Bogart15:11:40

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:

  ;; 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
  (-> zloc z/root)
  ;; non-final testing branch
  (and (-> zloc z/down testing?)
       (not (-> zloc z/down basic-test?)))
  (recur (-> zloc z/remove*))
  (recur (-> zloc z/right)))

Noah Bogart15:11:34


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


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

👍 1

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


Actually end, but I don’t think you need to distract yourself with those nuances right now.

Noah Bogart15:11:29

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

Noah Bogart15:11:52

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!

Noah Bogart15:11:28

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

Noah Bogart15:11:40

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


@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

Cool thanks for sharing!


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

Noah Bogart19:11:15

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


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.

Noah Bogart19:11:24

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

Noah Bogart21:11:11

Thank you to both of you!