4 ms·
Most common regex implementations are not composable at the language level but there are more modern alternatives like Pomsky [1] that introduce bindings and ac
by aziis98 2y ago
Most common regex implementations are not composable at the language level but there are more modern alternatives like Pomsky [1] that introduce bindings and actually make regexes composable expressions.
By the way regular expressions are "composable" by definition as they are defined recursively as (in their simplest form)
- ε is the regex that matches the empty string
- given regexes A and B we can construct the new regex AB that matches first the regex A followed by B
- given regexes A and B we can construct A|B that matches A or B
- given a regex A the regex A* matches any number of repeated occurrences of A
Then for some reason languages like javascript don't provide a way of constructing
/foo/.concat(/bar/) // equivalent to /foobar/
but that is another problem.
[1]: https://pomsky-lang.org/ https://pomsky-lang.org/
- almostgotcaught 2y ago> - given regexes A and B we can construct the new regex AB that matches first the regex A followed by B > - given regexes A and B we can construct A|B that matches A or B Concatenation and alternation is not what one typically imagines when they utter the word composition (unless you expect me to understand "composition over inheritance" to mean actually "just use two classes instead of one").
- mportela 2y agoHmm, concatenation and alternation are exactly what I thought of when reading the work "composition" (I probably had functional programming in mind). I'm curious. What came to your mind for "composition"?
- deleted 2y ago[deleted]
- almostgotcaught 2y agoI already said it: what does the phrase "composition over inheritance" mean? > probably had functional programming in mind Then you should have no trouble recognizing that there is no analog to `f . g . h` for regexes.