Pattern matching in other languages

I just noted that pattern matching of some sort was introduced in python 3.10
https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching

I guess there is destructuring in ES6 syntax in javascript.

I wonder

  1. How are pattern matching in these languages differ?
  2. Who started pattern matching first? :rofl: Which language?
  3. What are other ideas you have seen being adopted outside Elixir which were Elixir originals? :sweat_smile:
2 Likes

Afaik, no one outside Erlang-world can do binary pattern matching (which is really great if you need binary pattern matching).

Pattern matching is not an Elixir nor Erlang original.

The original implementation of pattern matching in erlang is based on this book https://www.microsoft.com/en-us/research/uploads/prod/1987/01/slpj-book-1987.pdf

2 Likes

when you bring up this great book, I have to say, that Peyton Jones and especially Wadler are fantastic speakers. This is one of my favourite talks and the best plea for functional programming I know: "Propositions as Types" by Philip Wadler - YouTube
(You can safely skip the exhausting minutes 9-24 if you’re not “ready to learn about the hilarious subject of comptutablility theory”)

1 Like

Rust also has quite nice pattern matching: Patterns and Matching - The Rust Programming Language

Came to use Rust only recently, trying to write some smart contracts for terra blockchain. In many ways it reminded me of Elixir actually, with similar terminology and some of the goodies we like in Elixir. Going to Rust from Elixir might actually be easier than from any other language. It felt very friendly really, I like Rust :slight_smile:

1 Like