[Python-ideas] Pattern Matching Syntax
Steven D'Aprano
steve at pearwood.info
Fri May 4 07:39:14 EDT 2018
On Thu, May 03, 2018 at 09:04:40PM +0100, Ed Kellett wrote:
> On 2018-05-03 19:57, Chris Angelico wrote:
> > Got it. Well, I don't see why we can't use Python's existing primitives.
> >
> > def hyperop(n, a, b):
> > if n == 0: return 1 + b
> > if n == 1: return a + b
> > if n == 2: return a * b
> > if n == 3: return a ** b
> > if n == 4: return a *** b
> > if n == 5: return a **** b
> > if n == 6: return a ***** b
> > ...
>
> Well, it'd be infinitely long, but I suppose I'd have to concede that
> that's in line with the general practicality level of the example.
Yes, but only countably infinite, so at least we can enumerate them
all. Eventually :-)
And aside from the tiny niggle that *** and higher order operators are
syntax errors...
Its not a bad example of the syntax, but it would be considerably more
compelling a use-case if it were something less obscure and impractical.
--
Steve
More information about the Python-ideas
mailing list