Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post walk order seems incorrect #123

Closed
lread opened this issue Feb 2, 2021 · 0 comments
Closed

post walk order seems incorrect #123

lread opened this issue Feb 2, 2021 · 0 comments
Labels
Projects

Comments

@lread
Copy link
Collaborator

lread commented Feb 2, 2021

While looking at #69, I decided to add some tests to make sure any changes I made did not affect walk order.

To refresh my brain on pre-walk and post-walk traversal, I read:

Rewrite-clj's prewalk travesal seems to match the above descriptions, but postwalk traversal seems off.

(defn- walk-order-tester [walk-fn s]
 (let [zloc (base/of-string s)
       visits (atom [])] 
   (walk-fn zloc (fn [zloc]
                     (swap! visits conj (base/string zloc))
                     zloc))
      @visits))

;; prewalk looks good:
 (walk-order-tester w/prewalk "(1 (2 3 (4 5) 6 (7 8)) 9)")
  ;; => ["(1 (2 3 (4 5) 6 (7 8)) 9)"
  ;;     "1"
  ;;     "(2 3 (4 5) 6 (7 8))"
  ;;     "2"
  ;;     "3"
  ;;     "(4 5)"
  ;;     "4"
  ;;     "5"
  ;;     "6"
  ;;     "(7 8)"
  ;;     "7"
  ;;     "8"
  ;;     "9"]

;; but postwalk looks wrong
  (walk-order-tester w/postwalk "(1 (2 3 (4 5) 6 (7 8)) 9)")
  ;; => ["9"
  ;;     "8"
  ;;     "7"
  ;;     "(7 8)"
  ;;     "6"
  ;;     "5"
  ;;     "4"
  ;;     "(4 5)"
  ;;     "3"
  ;;     "2"
  ;;     "(2 3 (4 5) 6 (7 8))"
  ;;     "1"
  ;;     "(1 (2 3 (4 5) 6 (7 8)) 9)"]

For postwalk, I would have expected:

["1"
 "2"
 "3"
 "4"
 "5"
 "(4 5)"
 "6"
 "7"
 "8"
 "(7 8)"
 "(2 3 (4 5) 6 (7 8))"
 "9"
 "(1 (2 3 (4 5) 6 (7 8)) 9)"]
@lread lread added the bug label Feb 2, 2021
@lread lread added this to In Progress in rewrite-clj Feb 2, 2021
@lread lread moved this from In Progress to Fixed in v1 branch in rewrite-clj Feb 3, 2021
@lread lread closed this as completed in b6ec3c6 Mar 10, 2021
rewrite-clj automation moved this from Fixed in v1 branch to Done Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant