Le mar. 18 sept. 2018 à 13:39, Tobias Kohn a écrit :
> Hello Everyone,
>
> Please excuse my being late for properly responding to the last thread on
> "Pattern Matching Syntax" [1]. As Robert Roskam has already pointed out at
> the beginning of that thread, there has been much previous discussio
Needless to say it's interesting to see what others language have (pros and
cons), I'm thinking about Scala for example (but I'm sure perl can show us
a long list of pros and cons).
Le mar. 18 sept. 2018 à 13:38, Tobias Kohn a écrit :
> Hello Everyone,
>
> Please excuse my being late for properl
Hey Steven,
I'm also at PyCon. Shall we take this off list and attempt to meet up and
discuss?
On Friday, May 11, 2018 at 12:36:32 PM UTC-4, ste...@rigetti.com wrote:
>
> Hi everyone, I’m also a first time poster to python-ideas so I apologize
> if reviving a week old thread is bad form. I emai
Hi everyone, I’m also a first time poster to python-ideas so I apologize if
reviving a week old thread is bad form. I emailed Guido out of the blue to
share some thoughts on the JavaScript pattern matching proposal’s
applicability to Python and he encouraged me to post those thoughts here.
The
[Tim]
... I liked the way he _reached_ that conclusion: by looking at real-
life Python code that may have been written instead to use constructs
"like this". I find such examination far more persuasive than abstract
arguments or made-up examples.
[Serhiy]
>>> I would like to
05.05.18 09:23, Tim Peters пише:
[Tim]
... I liked the way he _reached_ that conclusion: by looking at real-
life Python code that may have been written instead to use constructs
"like this". I find such examination far more persuasive than abstract
arguments or made-up examples.
[Serhiy Sto
[Tim]
>> ... I liked the way he _reached_ that conclusion: by looking at real-
>> life Python code that may have been written instead to use constructs
>> "like this". I find such examination far more persuasive than abstract
>> arguments or made-up examples.
[Serhiy Storchaka ]
> I would like t
04.05.18 20:48, Tim Peters пише:
[Guido]
Can I recommend going slow here? This is a very interesting topic where many
languages have gone before. I liked Daniel F Moisset's analysis about the
choices of a language designer and his conclusion that match should be a
statement.
Just to be annoyin
[Guido]
> Can I recommend going slow here? This is a very interesting topic where many
> languages have gone before. I liked Daniel F Moisset's analysis about the
> choices of a language designer and his conclusion that match should be a
> statement.
Just to be annoying ;-) , I liked the way he _r
Can I recommend going slow here? This is a very interesting topic where
many languages have gone before. I liked Daniel F Moisset's analysis about
the choices of a language designer and his conclusion that match should be
a statement.
I just noticed the very similar proposal for JavaScript linked
On 2018-05-04 08:26, Jacco van Dorp wrote:
> Would this be valid?
>
> # Pattern matching with guards
> x = 'three'
>
> number = match x:
> 1 => "one"
> y if y is str => f'The string is {y}'
> z if z is int => f'the int is {z}'
> _ => "anything"
>
> print(number) # The string is
On Sat, May 5, 2018 at 12:45 AM, Daniel Moisset wrote:
>> (3) Unlike a case/switch statement, there's no implication that the
>> compiler could optimise the order of look-ups; it is purely top to
>> bottom.
>
>
> [we are talking about a multi-branch pattern matching statement now, not
> just "aptt
This email from Steve has some good questions, let me try to help organize
ideas:
On 4 May 2018 at 13:11, Steven D'Aprano wrote:
> I'll make a start, and you can correct me if I get any of it wrong.
>
> (1) Pattern matching takes a value, and compares it to a series of
> *patterns* until the fir
Note that most languages that you mentioned as references are functional
(so they don't have a statement/expression distinction like Python has),
and those that are not, have matching statements. The only exception is
Javascript, but in Javascript the distinction is not that
hard given that it has
On Thu, May 03, 2018 at 11:36:27AM -0700, Robert Roskam wrote:
> So I started extremely generally with my syntax, but it seems like I should
> provide a lot more examples of real use.
Yes, real-life examples will be far more compelling and useful than made
up examples and pseudo-code.
Also, I
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: ret
Would this be valid?
# Pattern matching with guards
x = 'three'
number = match x:
1 => "one"
y if y is str => f'The string is {y}'
z if z is int => f'the int is {z}'
_ => "anything"
print(number) # The string is three
If so, why are y and z both valid here ? Is the match variab
On 2018-05-03 20:17, Chris Angelico wrote:
>> def convert_time_to_timedelta_with_match(unit:str, amount:int, now:date):
>> return match unit:
>> x if x in ('days', 'hours', 'weeks') => timedelta(**{unit: amount})
>> 'months' => timedelta(days=30 * amount)
>> 'years' => timedelta(day
On 5/3/2018 8:41 AM, Robert Roskam wrote:
However, I don't see that the conversation ever really resolved, so I'd
like restart the conversation on some kind of pattern matching syntax in
Python.
For the cases not handled by dicts, I believe chained conditional
expressions work.
"""
# Patte
On 5/3/2018 9:16 AM, Joao S. O. Bueno wrote:
(sorry - my aboe message is about using a dictionary - the "=>" weird
tokens should j=be just plain ":" -
the point is that Python açready has syntax to do what is asked)
On 3 May 2018 at 10:15, Joao S. O. Bueno wrote:
What about instead of
number
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
>
On Fri, May 4, 2018 at 5:02 AM, Robert Roskam wrote:
> Hey Chris,
>
> Thanks for bringing that up! Before submitting this, I actually had the
> syntax for multiple matches for one arm being separated by or. And frankly I
> just didn't like how that looked for more than 3 items:
>
> '1' or '2' or '
Hey Chris,
Thanks for bringing that up! Before submitting this, I actually had the
syntax for multiple matches for one arm being separated by or. And frankly
I just didn't like how that looked for more than 3 items:
'1' or '2' or '3' or '4' or '5' vs '1', '2', '3', '4', '5'
But you're right.
On Fri, May 4, 2018 at 4:40 AM, Steven D'Aprano wrote:
> On Fri, May 04, 2018 at 04:01:55AM +1000, Chris Angelico wrote:
>> On Fri, May 4, 2018 at 3:18 AM, Ed Kellett wrote:
>
>> > def hyperop(n, a, b):
>> > return match (n, a, b):
>> > (0, _, b) => b + 1
>> > (1, a, 0) => a
>
On Fri, May 4, 2018 at 4:36 AM, Robert Roskam wrote:
> Hey Chris,
>
> So I started extremely generally with my syntax, but it seems like I should
> provide a lot more examples of real use. Examples are hard. Here's my
> hastily put together example from an existing piece of production code:
>
>
>
On Fri, May 04, 2018 at 04:01:55AM +1000, Chris Angelico wrote:
> On Fri, May 4, 2018 at 3:18 AM, Ed Kellett wrote:
> > def hyperop(n, a, b):
> > return match (n, a, b):
> > (0, _, b) => b + 1
> > (1, a, 0) => a
> > (2, _, 0) => 0
> > (_, _, 0) => 1
> >
Hey Chris,
So I started extremely generally with my syntax, but it seems like I should
provide a lot more examples of real use. Examples are hard. Here's my
hastily put together example from an existing piece of production code:
# Existing Production Code
from datetime import timedelta, date
f
Calculating the Ackermann function as Knuth up-arrows really has little
practical user. The first few values are well known, the rest won't be
calculated before the heat death of the universe.
On Thu, May 3, 2018, 2:02 PM Chris Angelico wrote:
> On Fri, May 4, 2018 at 3:18 AM, Ed Kellett
> wrot
On Fri, May 4, 2018 at 3:18 AM, Ed Kellett wrote:
> I believe the intention in the example you quoted is syntax something like:
>
> ::=
>| "if"
>
> where the expression is a guard expression evaluated in the context of
> the matched pattern.
>
> IOW, it could be written
On 2018-05-03 18:53, Rhodri James wrote:
> On 03/05/18 18:18, Ed Kellett wrote:
>> It's a proposal for new syntax.
>
> I snipped the rest because fundamentally you have failed to explain your
> new syntax in any clear way. You've given examples of varying levels of
> complexity but failed to expl
On 03/05/18 18:18, Ed Kellett wrote:
It's a proposal for new syntax.
I snipped the rest because fundamentally you have failed to explain your
new syntax in any clear way. You've given examples of varying levels of
complexity but failed to explain what any of them should actually do in
words
On 2018-05-03 15:02, Jacco van Dorp wrote:
>> # Pattern matching with guards
>> x = 'three'
>>
>> number = match x:
>>1 => "one"
>>y if y is str => f'The string is {y}'
>>_ => "anything"
>>
>> print(number) # The string is three
>
> I think you meant to use isinstance(y, str) ?
> This
On Fri, May 4, 2018 at 12:29 AM, Robert Roskam wrote:
> Hey Joao,
>
> Thanks for providing me feedback on this idea!
>
> For the simplistic example at that you select, yes, you absolutely can do
> this as it stands atm. However, the examples I provided further along aren't
> as easily accomplished
Hey Joao,
Thanks for providing me feedback on this idea!
For the simplistic example at that you select, yes, you absolutely can do
this as it stands atm. However, the examples I provided further along
aren't as easily accomplished, nor is something like this:
x = -1
result = match x:
x:int
> # Pattern matching with guards
> x = 'three'
>
> number = match x:
>1 => "one"
>y if y is str => f'The string is {y}'
>_ => "anything"
>
> print(number) # The string is three
I think you meant to use isinstance(y, str) ?
This looks like an incomplete ternary as well, missing the els
> "Stéfane" == Stéfane Fermigier writes:
Stéfane> On Thu, May 3, 2018 at 2:41 PM, Robert Roskam
Stéfane> wrote:
>>
>> And for the sake of completeness, here are other languages with similar
>> syntax features and their associated documentation [...]
>>
Stéfane>
On Thu, May 3, 2018 at 2:41 PM, Robert Roskam
wrote:
>
> And for the sake of completeness, here are other languages with similar
> syntax features and their associated documentation [...]
>
Still for the sake of completeness, and without any judgement from me at
this point, a couple more, which ar
(sorry - my aboe message is about using a dictionary - the "=>" weird
tokens should j=be just plain ":" -
the point is that Python açready has syntax to do what is asked)
On 3 May 2018 at 10:15, Joao S. O. Bueno wrote:
> What about instead of
>
> number = match x:
> 1 => "one"
> 2 => "two
What about instead of
number = match x:
1 => "one"
2 => "two"
3 => "three"
10 => "ten"
_ => "anything"
number = {
1 => "one"
2 => "two"
3 => "three"
10 => "ten"
}.get(x, "anything")
No magic syntax with blocks starting inside an assignment, just to start
39 matches
Mail list logo