On Sun, Aug 08, 2021 at 11:30:20AM +0400, Abdulla Al Kathiri wrote:
> For me, it looks normal because I am used to seeing pattern matching
> for function parameters in functional programming languages.
Can you give us a few samples from other languages? The only one I know
is Haskell:
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
I don't *hate* that in Haskell, because Haskell is meant to be read
almost as mathematical definitions. But Python functions are
declarative, and Python code consists of statements which are executed
in a defined order. I don't think that's a good match for Haskell-style
syntax.
What's wrong with the straight-forward application of a match statement
inside the function body? As you suggest:
> def fib(*args):
> match args:
> case 0, : return 0
> case 1, : return 1
> case int(n), :
> return fib(n-1) + fib(n-2)
It costs one extra line (the match statement), but makes it explicit
what we're matching. And you save having to repeat the `def fib` for
every case.
Most importantly, it means that we only need one kind of pattern
matching syntax, instead of two.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WCOU56EW37ZAC76GNICXR5NOWNNR6GRN/
Code of Conduct: http://python.org/psf/codeofconduct/