This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-02
Channels
- # announcements (11)
- # aws (2)
- # babashka (42)
- # beginners (26)
- # calva (17)
- # cider (1)
- # clara (2)
- # clj-kondo (44)
- # clojars (30)
- # clojure (43)
- # clojure-australia (6)
- # clojure-europe (29)
- # clojure-gamedev (4)
- # clojure-greece (1)
- # clojure-nl (4)
- # clojure-spec (4)
- # clojure-uk (6)
- # clojurescript (28)
- # cursive (16)
- # data-science (1)
- # datahike (4)
- # datomic (26)
- # emacs (6)
- # events (3)
- # fulcro (11)
- # graalvm (7)
- # holy-lambda (118)
- # java (9)
- # jobs (1)
- # leiningen (3)
- # lsp (21)
- # luminus (2)
- # malli (13)
- # membrane-term (1)
- # music (1)
- # nrepl (3)
- # off-topic (38)
- # pedestal (2)
- # polylith (39)
- # re-frame (33)
- # reagent (7)
- # releases (1)
- # remote-jobs (4)
- # rewrite-clj (28)
- # ring (21)
- # sql (2)
- # tools-deps (23)
- # vim (4)
- # xtdb (15)
okay, got zip/node
working!
looking very good, very promising
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
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))))))
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
if I call z/root
, how do I turn the result back into a zipper?
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)
@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`.
cool, thank you
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)))
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)))
@nbtheduke That might be because it's closely modelled after clojure.zip and clojure.zip behaves like that too
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.
excellent, that’s honestly what I’d kind of noticed but didn’t fully understand
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!
there’s no easy way to dedent a list
, is there? lol
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.
BTW, did you notice you have some orphaned empty tests like this (deftest runner-basic-actions)
?
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.
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
@nbtheduke Awesome job :)
Thank you to both of you!