3 ms·
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 strategie
by coliveira 2y ago
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.
- mananaysiempre 2y agoMatching 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.
- iamwil 2y agoSimon Peyton Jones (of Haskell) is working on Verse, a functional relational programming language, that merges the ideas of both functional and logical programming into one. It’s being done to facilitate Fortnite metaverse, as he’s doing this work at Epic. https://youtu.be/OJv8rFap0Nw?si=OmBT9CBJIxdJE1Jv https://youtu.be/OJv8rFap0Nw?si=OmBT9CBJIxdJE1Jv
- harrisi 2y agoErlang, 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.
- macintux 2y agoI mostly ignored Python until my job required it, about 8 years ago. Coming from Erlang, I was pleasantly astonished to find that I could use tuple pattern matching in function headers… until I discovered that was dropped in Python 3 and I had been using the mostly-dead version 2 runtime.
- harrisi 2y agoI think I'd call this destructuring, as opposed to patterns and matches, and Python still does it, just not in the function head. I do wish they went the opposite direction and made the feature better instead of keeping it as a weird assignment thing in the body. The match statement is a similarly unfortunate solution, in my opinion. Oh well. :)
- macintux 2y agoYou're correct, destructuring is the appropriate term. I checked the release notes, and the reason they removed it: no one was using it. I guess it's unsurprising, but sad.
- needlesslygrim 2y agoI'm curious, how does Swift have better pattern matching than Rust?
- sulam 2y agoThese are probably tied TBH.
- 2y ago