meander

wilkerlucio 2022-06-27T14:04:40.949389Z

hello, how can I make a pattern that says a key must not be in the map?

Ben Sless 2022-06-27T14:14:18.053479Z

Maybe by writing a pattern that fails (bottom) if it succeed in matching a key in a map? (and {k (some v)} fail)

wilkerlucio 2022-06-27T14:15:09.655339Z

I found that just using {:key nil} seems to work fine

Ben Sless 2022-06-27T14:23:27.596289Z

What if the key exists with a nil value? Is it possible?

wilkerlucio 2022-06-27T14:23:59.233389Z

I think in this case will match the same, which is fine for my use case but I can see some other case might wanna know the difference

noprompt 2022-06-27T19:36:52.820119Z

There is currently not a (clean) way to distinguish between a missing key and a key with a nil value. 😐

wilkerlucio 2022-06-27T19:38:36.554299Z

I think something in the direction of what match combinators do would be interesting to have in meander, for the case we are discussing they have the absent matcher (https://github.com/nubank/matcher-combinators#negative-matchers)

wilkerlucio 2022-06-27T19:39:10.499599Z

it is possible to make a custom syntax on meander for that?

noprompt 2022-06-27T19:45:10.298489Z

For interpreted Meander, sure, but for compiled, it’s possible but too much work for the time I am currently making for the project (which has only been on the zeta branch). The issue boils down to compiled meander resolving key values with get. We could switch to find for specific keys but, again, it’s a lot of work. A workaround be papered over with defsyntax

{& (m/scan [:foo ?x])}

noprompt 2022-06-27T19:45:50.659749Z

Use {} to ensure you get a map, then m/scan the keys. But that is really kinda ugly.

noprompt 2022-06-27T19:47:01.411369Z

{:foo ?foo & (not ?x) :as ?x}
Might work too.

noprompt 2022-06-27T19:47:38.320849Z

Right because if ?x is {} and & ?x succeeds then you know :foo isn’t a key.