meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
fbeline 2019-12-20T17:52:39.009300Z

hello, is it possible to do value manipulation with rewrite? ex: (facts ?d . !body ...) (deftest ?d . !body ...) ?d is a string and I want it to be a symbol (facts "foo bar" ...) to (deftest foo-bar ...)

jimmy 2019-12-20T18:00:02.010900Z

Should be able to do (m/app some-conversion-fn ?d)

jimmy 2019-12-20T18:00:18.011400Z

On the output of rewrite.

noprompt 2019-12-20T18:13:30.011700Z

@fe.belineb m/symbol also works on the right side

jimmy 2019-12-20T18:15:26.012400Z

Not with a string that has a space though right?

noprompt 2019-12-20T18:16:22.013Z

Yeah…

noprompt 2019-12-20T18:16:28.013300Z

(name (symbol "foo bar"))
;; => "foo bar"

noprompt 2019-12-20T18:16:43.013800Z

Good ’ol garbage in/garbage out.

noprompt 2019-12-20T18:17:12.014200Z

@fe.belineb Here are a couple examples

(m/rewrite "foo"
  (m/pred string? ?x)
  (m/symbol ?x))
;; => foo

(m/rewrite "foo"
  (m/pred string? ?x)
  (m/symbol ?x "bar"))
;; => foo/bar

(m/rewrite "foo"
  (m/pred string? ?x)
  (m/symbol "bar" ?x))
;; => bar/foo

noprompt 2019-12-20T18:18:04.014700Z

You can also do it all on the left side via

(m/rewrite "foo"
  (m/pred string? (m/app symbol ?x))
  ?x)
;; => foo

noprompt 2019-12-20T18:19:53.016600Z

Which may be safer.

jimmy 2019-12-20T18:20:18.017Z

The example above has a space and then is turned into snake case. That's why I said app instead of symbol.

fbeline 2019-12-20T18:20:40.017500Z

Nice I will take a look into it. The thing is that before converting it to a symbol I need to do some string manipulations, ex:

(facts "Testing account   creation")
to
(deftest testing-account-creation")

noprompt 2019-12-20T18:20:56.017900Z

Ah, didn’t catch that!

fbeline 2019-12-20T18:21:03.018200Z

is this case I will need to m/app the output right?

noprompt 2019-12-20T18:21:06.018400Z

Yah

noprompt 2019-12-20T18:21:38.019200Z

Like @jimmy suggested (m/app kebab-symbol) or whatever.

noprompt 2019-12-20T18:22:20.019800Z

Are you rewriting a test suite? 🙂

fbeline 2019-12-20T18:25:07.021400Z

that is the idea, taking a look into some options to do that. like rewrite-clj and https://comby.dev/ too

fbeline 2019-12-20T18:25:38.022200Z

do you believe that meader is a great fit for that?

fbeline 2019-12-20T18:28:25.023900Z

(talking about several thousands of test files)

jimmy 2019-12-20T18:30:29.025700Z

I think there are actually a few people in here doing similar things. Specifically with test suites. Haha. Seems like a popular thing to rewrite. Imo meander should be great for that.

noprompt 2019-12-20T18:33:25.027400Z

LOL, yeah, should be good for that, though I haven’t tried using it in conjunction with rewrite-clj . I suppose if I were doing it thought I’d probably just read forms out of files and apply rewrite rules to them, write the files, then apply formatting in post.

noprompt 2019-12-20T18:34:06.028300Z

One thing I keep meaning to try is rewrite a from to form’ then rewrite form’ to fipp printing instructions.

fbeline 2019-12-20T18:39:13.031100Z

yes, I am not 100% sure but formatting should not be "that hard", also some formatting issues is better than doing it manually 😂 .

fbeline 2019-12-20T18:44:38.035600Z

rewrite-clj preserves the indentation but it is much more difficult to work with. I remember that even for simple tasks as upgrading dependencies version at project.clj the code was hard to read.

jimmy 2019-12-20T18:59:47.037400Z

Definitely let use know if you encounter any problems. Seems like rewriting in meander and using something like cljfmt should get you most of the way there.

noprompt 2019-12-20T19:16:55.037900Z

> much more difficult to work with

noprompt 2019-12-20T19:18:07.039300Z

That was my memory of it (years ago). Not trying to speak ill of it; I was less experienced then. :man-shrugging:

fbeline 2019-12-20T19:38:37.043400Z

Thanks @jimmy and @noprompt, I will play around and see how it works at complicated scenarios. Any "news" I let you know

fbeline 2019-12-20T19:48:32.044400Z

Just about the question that I did previously, I solve it in that way:

(def facts->deftest
  (m*/bottom-up
    (m*/attempt
      (m*/rewrite
        (facts ?d . !body ...) (deftest (m/app kebab-case ?d) . !body ...)))))

👍 2
noprompt 2019-12-20T22:02:37.048400Z

You can avoid the cost of the attempt by adding the clause ?x ?x at the bottom of that rewrite.