馃懡 marginalia

Is there something like a regexp-language, except generalized to sequences of objects? I want to be able to express patterns of properties in a list, and find matches in a way that isn't if((foo(i j) && bar(i j 1) && baz(i j 2)) || foo(i j) && ...

3 years ago 路 馃憤 aka_dude

Actions

馃憢 Join Station

9 Replies

馃懡 marginalia

@aka_dude Yeah, something like that. I'm specifically looking for a way of expressing a matcher against repeating patterns (like, with regexps), but matching against object properties. Basically, if you generalize regexps from character traits to object traits 路 3 years ago

馃懡 aka_dude

I see you want to match on Java objects. Maybe one could create something handy like monadic parser in Java, too 路 3 years ago

馃懡 aka_dude

Is this just parsing? Parser is something that takes stream of symbols (of any kind) and either returns an error or parsed object. In purely functional languages like Haskell parsing looks very nice (see monadic parsers, e.g. Megaparsec)

This "symbols" may not be characters/bytes, anything works 路 3 years ago

馃懡 mntn

My bad, 636 is the tutorial, it was 622/634. https://www.python.org/dev/peps/pep-0636/ 路 3 years ago

https://www.python.org/dev/peps/pep-0636/

馃懡 mntn

Use a language with ML-style pattern matching. Python now supports this thanks to PEP 636. 路 3 years ago

馃懡 mc

Perl/Raku 路 3 years ago

馃懡 marginalia

No these are objects, like Java-objects, not strings. If they were strings I could just use regexp. I don't want to have to serialize them down to strings just so I can find repetitions :-( 路 3 years ago

馃懡 kevinsan

XPath/XQuery or jq? Assuming you can feed your list as XML or JSON. Or maybe encode your list as text and actually use regexps? 路 3 years ago

馃懡 marginalia

(also, explicit state machines are an implicit surrender to the problem of finding a good abstraction) 路 3 years ago