[Python-Dev] Remove formatter module

2020-11-23 Thread Dong-hee Na
A few days ago, Terry J. Reedy created the issue about the formatter module. (https://bugs.python.org/issue42299) The issue is mainly about testing code but also discussing the removal of the module. I noticed that the formatter module was deprecated in 3.4 and it was originally scheduled to be re

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Eric V. Smith
On 11/23/2020 4:49 PM, David Mertz wrote: On Mon, Nov 23, 2020, 4:32 PM Eric V. Smith I just commented on Steve's post over on Discourse. The problem with this is that the called function (m.case, here) needs to have access to the caller's namespace in order to resolve the expre

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Eric V. Smith
On 11/23/2020 3:44 PM, David Mertz wrote: I have a little bit of skepticism about the pattern matching syntax, for similar reasons to those Larry expresses, and that Steve Dower mentioned on Discourse. Basically, I agree matching/destructuring is a powerful idea.  But I also wonder how much

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Eric V. Smith
On 11/23/2020 5:44 PM, David Mertz wrote: I'd put the question this way: assuming Matcher can be written (with a bit of stack magic), and assuming that the strings inside m.case() calls are exactly the same mini-languague PEP 634 proposes, would you want a syntax change? N

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread David Mertz
> > I'd put the question this way: assuming Matcher can be written (with a bit > of stack magic), and assuming that the strings inside m.case() calls are > exactly the same mini-languague PEP 634 proposes, would you want a syntax > change? > > No, I wouldn't! > Is one of us mixing up negations? Are

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Greg Ewing
On 24/11/20 9:44 am, David Mertz wrote: m = Matcher(arbitrary_expression) if m.case("StringNode(s)"):     process_string(m.val) elif m.case("[a, 5, 6, b]"):     process_two_free_vars(*m.values) elif m.case("PairNone(a, b)"):     a, b = m.values     process_pair(a, b) elif m.case("DictNode"):

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Greg Ewing
On 24/11/20 9:31 am, Brian Coleman wrote: In my opinion, the object oriented solution to this problem is to use the visitor pattern. Which is a good thing only if you believe that OO solutions are always better than non-OO ones. IMO, the visitor pattern is a workaround for when your language

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Ethan Furman
On 11/23/20 1:49 PM, David Mertz wrote: On Mon, Nov 23, 2020, 4:32 PM Eric V. Smith I just commented on Steve's post over on Discourse. The problem with this is that the called function (m.case, here) needs to have access to the caller's namespace in order to resolve the expressions, such as

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Steven D'Aprano
On Mon, Nov 23, 2020 at 08:44:21PM +, David Mertz wrote: > Basically, I agree matching/destructuring is a powerful idea. But I also > wonder how much genuinely better it is than a library that does not require > a language change. For example, I could create a library to allow this: > > m =

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread David Mertz
On Mon, Nov 23, 2020, 4:32 PM Eric V. Smith > I just commented on Steve's post over on Discourse. The problem with this > is that the called function (m.case, here) needs to have access to the > caller's namespace in order to resolve the expressions, such as StringNode > and PairNone. This is one

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Brian Coleman
David Mertz wrote: > On Mon, Nov 23, 2020 at 9:02 PM Brian Coleman brianfcole...@gmail.com > wrote: > > Basically, I > > agree matching/destructuring is a powerful idea. But I also > > wonder how much genuinely better it is than a library that does not > > require > > a language change. For examp

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread David Mertz
On Mon, Nov 23, 2020 at 9:02 PM Brian Coleman wrote: > > Basically, I agree matching/destructuring is a powerful idea. But I also > > wonder how much genuinely better it is than a library that does not > require > > a language change. For example, I could create a library to allow this: > >

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Brian Coleman
David Mertz wrote: > I have a little bit of skepticism about the pattern matching syntax, for > similar reasons to those Larry expresses, and that Steve Dower mentioned on > Discourse. > Basically, I agree matching/destructuring is a powerful idea. But I also > wonder how much genuinely better it

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread David Mertz
I have a little bit of skepticism about the pattern matching syntax, for similar reasons to those Larry expresses, and that Steve Dower mentioned on Discourse. Basically, I agree matching/destructuring is a powerful idea. But I also wonder how much genuinely better it is than a library that does

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Brian Coleman
Antoine Pitrou wrote: > On Mon, 23 Nov 2020 16:15:12 - > "Brian Coleman" brianfcole...@gmail.com > wrote: > > Furthermore, Python has a regular expression module > > which implements it's own DSL for the purpose of matching string patterns. > > Regular > > expressions, in a similar way to patt

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Brian Coleman
Larry Hastings wrote: > On 11/23/20 8:15 AM, Brian Coleman wrote: > > def process(root_node: Node): > > def process_node(node: Node): > > if isinstance(node, StringNode): > > return node.value > > elif isinstance(node, NumberNode): > > return float(n

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Ethan Furman
On 11/23/20 12:05 PM, Chris Angelico wrote: On Tue, Nov 24, 2020 at 7:00 AM Ethan Furman wrote: On 11/23/20 11:06 AM, Larry Hastings wrote: > On 11/23/20 8:15 AM, Brian Coleman wrote: >> def process(root_node: Node): >> def process_node(node: Node): >> if isinstance(node,

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread David Mertz
On Mon, Nov 23, 2020, 2:58 PM Ethan Furman > >> if isinstance(node, StringNode): > >> return node.value > >> elif isinstance(node, NumberNode): > >> return float(node.value) > >> elif isinstance(node, ListNode): > >> return [p

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Chris Angelico
On Tue, Nov 24, 2020 at 7:00 AM Ethan Furman wrote: > > On 11/23/20 11:06 AM, Larry Hastings wrote: > > On 11/23/20 8:15 AM, Brian Coleman wrote: > >> def process(root_node: Node): > >> def process_node(node: Node): > >> if isinstance(node, StringNode): > >> return

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Ethan Furman
On 11/23/20 11:06 AM, Larry Hastings wrote: > On 11/23/20 8:15 AM, Brian Coleman wrote: >> def process(root_node: Node): >> def process_node(node: Node): >> if isinstance(node, StringNode): >> return node.value >> elif isinstance(node, NumberNode): >>

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Antoine Pitrou
On Mon, 23 Nov 2020 16:15:12 - "Brian Coleman" wrote: > > Furthermore, Python has a regular expression module which implements it's own > DSL for the purpose of matching string patterns. Regular expressions, in a > similar way to pattern matching, > allow string patterns to be expressed i

[Python-Dev] Re: Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Larry Hastings
On 11/23/20 8:15 AM, Brian Coleman wrote: def process(root_node: Node): def process_node(node: Node): if isinstance(node, StringNode): return node.value elif isinstance(node, NumberNode): return float(node.value) elif isinstance(node, Lis

[Python-Dev] Advantages of pattern matching - a simple comparative analysis

2020-11-23 Thread Brian Coleman
Take as an example a function designed to process a tree of nodes similar to that which might be output by a JSON parser. There are 4 types of node: - A node representing JSON strings - A node representing JSON numbers - A node representing JSON arrays - A node representing JSON dictionaries The

[Python-Dev] Re: Words rather than sigils in Structural Pattern Matching

2020-11-23 Thread Baptiste Carvello
Hi, Le 23/11/2020 à 01:41, Greg Ewing a écrit : > On 23/11/20 7:49 am, Daniel Moisset wrote: >> Look at the following (non-pattern-matching) snippet: >> >>     event = datetime.date(x, month=y, day=z) > > The only names that are treated as lvalues there are to the left > of an '='. […] This is a

[Python-Dev] Re: Words rather than sigils in Structural Pattern Matching

2020-11-23 Thread Brian Coleman
Greg Ewing wrote: > On 23/11/20 7:49 am, Daniel Moisset wrote: > > Look at the following (non-pattern-matching) > > snippet: > > event = datetime.date(x, month=y, day=z) > > > > The only names that are treated as lvalues there are to the left > of an '='. The rules are a lot simpler. > One of the