Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by macintux on Thursday November 07, 2024 @04:10PM
(#42081050)
I 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.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by harrisi on Thursday November 07, 2024 @04:57PM
(#42081544)
I 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. :)
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by macintux on Thursday November 07, 2024 @06:26PM
(#42082299)
You'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.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by needlesslygrim on Thursday November 07, 2024 @08:53PM
(#42083333)
I'm curious, how does Swift have better pattern matching than Rust?
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by sulam on Thursday November 07, 2024 @09:16PM
(#42083456)
These are probably tied TBH.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by harrisi on Friday November 08, 2024 @11:18PM
(#42092518)
I agree with sulam, in that I think they're roughly equally nice to work with. Not as powerful as Erlang/Elixir, but more capable than Python.
There's a decent discussion from a few years ago on hn, as well: https://news.ycombinator.com/item?id=24662262
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog)
by coliveira on Friday November 08, 2024 @10:37AM
(#42087634)
I looked at Erlang and it is closest to the Prolog idea (clearly because Erlang was originally implemented in Prolog). Other languages are not really what I mean by pattern matching, the matching should go on the selection of functions to apply to a particular parameter expression. In the compiled world, C++ is the one that gets closest to this behavior. Python would be able to do it due to its dynamic nature, but for some reason it decided not to implement this feature.
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.