11 ms·
So regexes tend to be inscrutable and uncomposable largely because of legacy, and partly because your operators naturally clash with the characters you're tryin
by ben509 6y ago
So regexes tend to be inscrutable and uncomposable largely because of legacy, and partly because your operators naturally clash with the characters you're trying to match.
When Larry Wall was designing Rake nee Perl 6, he started by throwing out the POSIX baggage[1] to make the new regexes more readable. I think the common cases are far more readable, though you can judge for yourself.
It definitely improves composing regexes by providing a sane, built-in syntax for it.[2]
And since you're reading this, Raku also offers a full parser through its grammars.[3]
[1]: https://design.raku.org/S05.html#Simplified_lexical_parsing_of_patterns https://design.raku.org/S05.html#Simplified_lexical_parsing_...
[2]: https://docs.raku.org/language/regexes#Regex_interpolation https://docs.raku.org/language/regexes#Regex_interpolation
[3]: https://docs.raku.org/language/grammars.html https://docs.raku.org/language/grammars.html
- thesz 6y agoWhat Pike did is creation of language feature. Original post talks about library. Libraries in well-typed languages are of about same power as language features and they are within reach of ordinary programmer. If you need a library, you can write it and use and publish. If you need a (change of) language feature, you have to convince others to write that for you.
- bmn__ 6y agoThat claim is false, I just need to bring one counter-example to disprove it. In Perl, regex is a language feature, yet it can be easily supplanted with a library that anyone can use and publish: https://metacpan.org/search?q=re%3A%3Aengine%3A%3A https://metacpan.org/search?q=re%3A%3Aengine%3A%3A It is not necessary to convince the Perl maintainers to write that for you.
- thesz 6y agoYou, from my point of view, disproved nothing. Can you intersperse regexps-as-language-feature with regexps-as-a-library? If answer is "yes", then, I think, you actually proven my point and what is language feature is, actually, a library in disguise. A special kind of library, so to say. If answer is "no", then if you miss something in first thing (an ability to add arbitrary parsing from these libraries, for example) you need to convince language maintainers to work for you, at least, review your work and your proposal.
- ben509 6y agoEven in the OP, the author is already using NSRegularExpression, because Swift doesn't have regular expressions built in. And if Next can write NSRegularExpression, anyone can write their own library that uses a better syntax and that supports interpolation. There's also no reason why a pure library has to make a single string its interface. For instance, in Python I might use overloaded operators: ((R('foo') | 'bar') + 'tholeme' + {'w', 'W'})[1:7] to mean: r'((foo|bar)tholeme[wW]){1,7}' There are some rough edges because you're abusing operator overloading, for sure, but expressing a regex is fundamentally composing assertions with operators. It doesn't _require_ any special syntax. And some languages give you a lot of power to write your own DSLs that will feel more native, e.g. Scheme[1], Haskell[2], Ruby and so forth. [1]: https://docs.racket-lang.org/guide/macros.html https://docs.racket-lang.org/guide/macros.html [2]: https://wiki.haskell.org/Template_Haskell https://wiki.haskell.org/Template_Haskell