meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
noprompt 2020-06-01T16:27:28.347900Z

@dominicm Whats flagged unused?

dominicm 2020-06-01T16:28:41.348100Z

@noprompt For something like:

{:a ?a :b ?b} (+ ?b 10)
?a would be unused, but you're using it to ensure :a is present… Although maybe I'm doing it wrong :)

noprompt 2020-06-01T16:31:12.349700Z

{:a (m/some) :b ?b} (+ ?b 10)

dominicm 2020-06-01T16:33:41.350400Z

@noprompt Ah, so maybe my hack is sufficient then. If I get some energy I'll play around with it.

dominicm 2020-06-01T16:33:46.350600Z

Oh, hmm, that's not the same?

dominicm 2020-06-01T16:33:56.350800Z

{:a nil} should match {:a ?a}

noprompt 2020-06-01T16:34:13.351100Z

It’ll also match {:no-a here}

noprompt 2020-06-01T16:37:28.353300Z

Going back and forth here on the most delicate way to express this but, eh, I can’t tactfully say it better: that macroexpand idea is a mixed bag.

dominicm 2020-06-01T16:38:16.353900Z

It's a difficult set of constraints to balance. I'm thinking that core.match and meander are probably the major use-cases for it.

noprompt 2020-06-01T16:38:40.354400Z

I stopped using clj-kondo because of all the complaints about variables it didn’t understand in macros.

noprompt 2020-06-01T16:39:08.355Z

IMHO some kind of symbolic execution would probably be the best.

noprompt 2020-06-01T16:39:24.355400Z

But its a lot of work.

dominicm 2020-06-01T16:39:41.355500Z

yeah, it is. I do wonder if sci could just run meander tbh.

noprompt 2020-06-01T16:39:53.355700Z

I was thinking that too.

dominicm 2020-06-01T16:40:22.356400Z

matchete might make a good candidate also.

noprompt 2020-06-01T16:40:35.356900Z

I made a thing for code search/replace about a year ago but I never made it into a solid stand alone thing.

dominicm 2020-06-01T16:40:51.357400Z

Ultimately, whatever we would implement only need be "good enough" that 99% of my annoyances with meander linting go away :)

snoe 2020-06-01T16:40:55.357600Z

let me know if you figure it out, clojure-lsp has to keep expanding it's macro-defs for handling the problem 😞

noprompt 2020-06-01T16:40:56.357800Z

We could export an interpreter pretty easily.

noprompt 2020-06-01T16:41:38.358700Z

Its been an outstanding issue for a while.

noprompt 2020-06-01T16:42:39.359800Z

@snoe I’m putting a sticky on my monitor to remind me to get familiar with clojure-lsp this week.

noprompt 2020-06-01T16:43:54.360800Z

@dominicm Seems like clj-kondo would have an off switch.

noprompt 2020-06-01T16:43:58.361Z

For specific forms.

noprompt 2020-06-01T16:44:17.361200Z

Linters. 💣

dominicm 2020-06-01T16:45:00.361300Z

@noprompt you can, yeah. But it's nice to get some feedback within those forms. Consider my try+, I'd have to disable linting in the whole try+ macro, so it wouldn't catch this:

(try+
  (let [x] …))

dominicm 2020-06-01T16:45:45.361500Z

To clarify, kondo already has the off-switch for specific forms :)

noprompt 2020-06-01T16:45:53.361700Z

This is one of the reasons I like the idea of “notation” over macros.

noprompt 2020-06-01T16:46:05.362100Z

Because with notation its simply a symbolic transformation.

dominicm 2020-06-01T16:47:04.363300Z

notation?

noprompt 2020-06-01T16:47:13.363500Z

Macros can have arbitrary code run which is super powerful but comes at the expense of increased analysis difficulty.

dominicm 2020-06-01T16:47:19.363700Z

Right

noprompt 2020-06-01T16:47:26.363900Z

defsyntax has this problem.

noprompt 2020-06-01T16:47:50.364500Z

I wanted to add defnotation which would basically be a symbolic rewrite rule instead of one that executes code.

noprompt 2020-06-01T16:48:19.365200Z

The advantage is that there is no code which can interfere with determining the shape of data coming out of the transform.

noprompt 2020-06-01T16:48:55.365900Z

At the cost of the power to manipulate strings and do many evil things therein. 😛

noprompt 2020-06-01T16:49:28.366100Z

Here’s the delta interpreter: https://gist.github.com/noprompt/085d100de4e85d7b643e438498e08b56

noprompt 2020-06-01T16:50:03.366700Z

Basically, you would parse the form and then interpret the match.

noprompt 2020-06-01T16:51:05.368Z

zeta kinda works both ways where the macro compiler uses the interpreter API when it as to and more advanced compilation moves when it can.

dominicm 2020-06-01T16:51:38.369400Z

Not at keyboard, but would {:a _} be the right form?

noprompt 2020-06-01T16:51:45.369600Z

epsilon probably should have been designed this way from the start but I started at “make a pattern matcher like core match that I maintain”

noprompt 2020-06-01T16:52:42.370600Z

No, you have to use m/some.

noprompt 2020-06-01T16:53:40.371600Z

With the ability to configure the compiler/parser/etc soon we can indicate that a map is strict.

dominicm 2020-06-01T16:54:31.373400Z

But m/some wouldn't match a nil value. That makes the behavior different.

noprompt 2020-06-01T16:54:49.373900Z

The decision to place the constraint on value is 99% due to the fact there is no operational/observable difference between (get {} :a) and (get {:a nil} :a).

noprompt 2020-06-01T16:54:56.374200Z

Yeah…

noprompt 2020-06-01T16:55:06.374500Z

That’s the screwed up thing.

dominicm 2020-06-01T16:55:53.375800Z

(get {:a nil} :a :default)

noprompt 2020-06-01T16:56:24.376400Z

This is why I like the pattern

(if-some [[_ value] (find m :a)]
  ,,,)

dominicm 2020-06-01T16:57:18.376800Z

Yeah, I sometimes use that too :)

dominicm 2020-06-01T16:57:30.377200Z

I try to be conscious of allowing nil

noprompt 2020-06-01T16:58:26.378100Z

Right. It was a decision I made early on. The tradeoff of matching on the result of get is this situation.

noprompt 2020-06-01T16:58:56.378700Z

But if you have strict map matching with find it can get really annoying.

noprompt 2020-06-01T17:00:50.379900Z

Maybe something like

^:strict {:a nil}

noprompt 2020-06-01T17:15:37.380300Z

BTW, if folks have any thoughts/ideas for flags share them on this PR: https://github.com/noprompt/meander/pull/124

noprompt 2020-06-01T17:17:28.381700Z

My primary goal for this patch at the moment is to be able to completely move any AST manipulation out of the matrix compiler and into the match syntax namespace and then have flags to turn them on/off

dominicm 2020-06-01T18:58:28.383400Z

I just realized we were talking past each other. https://cljdoc.org/d/meander/epsilon/0.0.421/doc/operator-overview#logic-variables title is optional in this example. I thought it was required.