logoalt Hacker News

coliveira11/07/20242 repliesview on HN

I always thought that pattern matching would be an excellent feature for other programming languages, but it seems that it hasn't become popular. Many strategies available to Prolog could become possible just by the addition of this feature. One possible implementation of the idea occurs with C++ templates specialized with numerical parameters. It also seems that Mathematica provides pattern matching, but I don't use that language.


Replies

mananaysiempre11/07/2024

Matching of patterns, with only a single occurrence allowed for each variable, is fairly popular in languages designed in the last two decades, isn’t it? A lot of those have or at least borrow from ML heritage, and that of course places a big emphasis on algebraic types and pattern matching. Full-blown unification remains niche, that’s true, but it’s just a fairly heavyweight feature, and I don’t really know how you’d integrate it without turning your language into (a superset of) Prolog.

show 1 reply
harrisi11/07/2024

Erlang, Elixir, Swift, Rust, Python, probably some others.

That list is roughly in order of how capable and useful the pattern matching is in each of those languages. Erlang was originally written in Prolog.

Also, I definitely agree it's a feature I miss everywhere when not using Erlang/Elixir.

show 3 replies