Re: Uniform Function Call Syntax (UFCS)

2014-06-09 Thread jongiddy
So, just to summarise the discussion: There was some very mild support for readable pipelines, either using UFCS or an alternative syntax, but the Pythonic way to make combinations of function and method applications readable is to assign to variables over multiple lines. Make the code read do

Re: Uniform Function Call Syntax (UFCS)

2014-06-09 Thread Ian Kelly
On Jun 8, 2014 9:56 PM, "Steven D'Aprano" > > which means that hasattr (which is defined by > > attempting to get the attribute and seeing if an exception is thrown) > > has to return True. > > Yes. And this is a problem why? Earlier in this thread I pointed out that returning True creates problem

Re: Uniform Function Call Syntax (UFCS)

2014-06-09 Thread Steven D'Aprano
On Mon, 09 Jun 2014 19:13:40 +1000, Chris Angelico wrote: > On Mon, Jun 9, 2014 at 7:09 PM, Steven D'Aprano > wrote: >> On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote: >> >>> In a word, >>> Python has predefined a handful of *generic functions/methods*, >> >> >> That's nine words :-) >

Re: Uniform Function Call Syntax (UFCS)

2014-06-09 Thread Chris Angelico
On Mon, Jun 9, 2014 at 7:09 PM, Steven D'Aprano wrote: > On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote: > >> In a word, >> Python has predefined a handful of *generic functions/methods*, > > > That's nine words :-) I'll explain in two words: We propose to marry your daughters. http://

Re: Uniform Function Call Syntax (UFCS)

2014-06-09 Thread Steven D'Aprano
On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote: > In a word, > Python has predefined a handful of *generic functions/methods*, That's nine words :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Monday, 9 June 2014 04:44:22 UTC+1, Chris Angelico wrote: > This could be solved, though, by having a completely different symbol > that means "the thing on my left is actually the first positional > parameter in the function call on my right", such as in your example: > > > plus(1, 2) | divid

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Marko Rauhamaa
Steven D'Aprano : > On Sun, 08 Jun 2014 18:56:47 +0300, Marko Rauhamaa wrote: >> In fact, what's the point of having the duality? >>x < y <==> x.__lt__(y) > > [...] > > Consider x + y. What happens? > > #1 First, Python checks whether y is an instance of a *subclass* of x. If > so, y gets pri

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 1:53 PM, Steven D'Aprano wrote: >> which means that hasattr (which is defined by >> attempting to get the attribute and seeing if an exception is thrown) >> has to return True. > > Yes. And this is a problem why? > > Obviously it would mean that the semantics of hasattr will

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
On Sun, 08 Jun 2014 18:56:47 +0300, Marko Rauhamaa wrote: > Paul Sokolovsky : > >> Python already has that - like, len(x) calls x.__len__() if it's >> defined > > In fact, what's the point of having the duality? > >len(x) <==> x.__len__() > >x < y <==> x.__lt__(y) > >str(x) <==> x.

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
On Mon, 09 Jun 2014 02:48:13 +1000, Chris Angelico wrote: > class Circle: > def squared(self): > raise NotImplementedError("Proven impossible in 1882") > > The trouble is that logically Circle does have a 'squared' attribute, > while 3 doesn't; and yet Python guarantees this: > > foo

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Roy Smith
In article <53952807$0$29988$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > (Note that Forth is brilliant here, as it exposes the argument stack and > gives you a rich set of stack manipulation commands.) As does PostScript (which, despite its reputation as a printer format, is

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 1:20 PM, Steven D'Aprano wrote: > On Mon, 09 Jun 2014 03:10:03 +1000, Chris Angelico wrote: > [...] >> Stdio.write_file("foo.png",Image.PNG.encode(Image.JPEG.decode( >> Stdio.read_file("foo.jpg")).autocrop().rotate(0.5).grey())); >> >> With UFCS, that could become perfect da

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
On Mon, 09 Jun 2014 03:10:03 +1000, Chris Angelico wrote: [...] > Actually, this is something that I've run into sometimes. I can't think > of any Python examples, partly because Python tends to avoid unnecessary > method chaining, but the notion of "data flow" is a very clean one - > look at shell

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 18:24:28 UTC+1, Ian wrote: > > But that would all be done in getattr, so I don't think it affects > hasattr's implementation at all. Since hasattr doesn't push anything > onto the stack, getattr doesn't have to care whether it was called > directly from Python or indirectl

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 11:13 AM, Chris Angelico wrote: > On Mon, Jun 9, 2014 at 3:08 AM, Ian Kelly wrote: >> On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote: >>> Except that it's even more complicated than that, because hasattr >>> wasn't defined in your module, so it has a different set o

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 3:08 AM, Ian Kelly wrote: > On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote: >> Except that it's even more complicated than that, because hasattr >> wasn't defined in your module, so it has a different set of globals. >> In fact, this would mean that hasattr would bec

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 2:24 AM, jongiddy wrote: > A contrived example - which of these is easier to understand? > > from base64 import b64encode > > # works now > print(b64encode(str(min(map(int, f.readlines()), key=lambda n: n % 10)), > b'?-')) > > # would work with UFCS > f.readlines().map(int)

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote: > Except that it's even more complicated than that, because hasattr > wasn't defined in your module, so it has a different set of globals. > In fact, this would mean that hasattr would become quite useless. hasattr is a builtin, so it has no

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 2:15 AM, jongiddy wrote: > One problem with your untested code, the superclasses would need to be > checked before using UFCS, so the structure is: > > try: > return super().__getattr__(attr) > except AttributeError: > # resolve using UFCS And then if UFCS finds no

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 10:24 AM, jongiddy wrote: > A contrived example - which of these is easier to understand? > > from base64 import b64encode > > # works now > print(b64encode(str(min(map(int, f.readlines()), key=lambda n: n % 10)), > b'?-')) > > # would work with UFCS > f.readlines().map(int

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 1:39 AM, jongiddy wrote: > e.g. I could define: > > def squared(x): > return x * x > > i = 3 > i.squared() => 9 > > j = AClassThatImplements__mul__() > j.squared() => whatever j * j returns > > but also: > class AnotherClass: > def __mul__(self, other): > ...

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
Hello, On Sun, 08 Jun 2014 18:56:47 +0300 Marko Rauhamaa wrote: > Paul Sokolovsky : > > > Python already has that - like, len(x) calls x.__len__() if it's > > defined > > In fact, what's the point of having the duality? > >len(x) <==> x.__len__() > >x < y <==> x.__lt__(y) > >str

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 9:56 AM, Marko Rauhamaa wrote: > Paul Sokolovsky : > >> Python already has that - like, len(x) calls x.__len__() if it's >> defined > > In fact, what's the point of having the duality? > >len(x) <==> x.__len__() > >x < y <==> x.__lt__(y) > >str(x) <==> x.__str__(

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 17:24:56 UTC+1, jongiddy wrote: > # would work with UFCS > f.readlines().map(int).min(key=lambda n: n % > 10).str().b64encode(b'?-').print() Ooops - map is the wrong way round to support UFCS in this case. However, with UFCS, I could fix this by changing it to smap, and

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 13:06:08 UTC+1, Paul Sokolovsky wrote: > > Getting x.foo() to call foo(x) is what's bigger problem, which has > serious performance and scoping confusion implications, as discussed in > other mails. The performance hit will only occur when the attribute access is about to

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Marko Rauhamaa
Paul Sokolovsky : > Python already has that - like, len(x) calls x.__len__() if it's > defined In fact, what's the point of having the duality? len(x) <==> x.__len__() x < y <==> x.__lt__(y) str(x) <==> x.__str__() etc. I suppose the principal reason is that people don't like UFCS.

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 15:59:14 UTC+1, Roy Smith wrote: > Why? I assume a language which promoted the global namespace to be in > the attribute search path (which, as far as I can tell, is what we're > talking about here) would implement hasattr and raising AttributeError > in a consistent w

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Roy Smith
In article <1dd863ba-09e5-439b-8669-db65f3e99...@googlegroups.com>, jongiddy wrote: > On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote: > > > > Also it doesn't sit well with Python's "one obvious > > way to do it" guideline, because it means there are > > *two* equally obvious ways t

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
Hello, On Sun, 8 Jun 2014 01:26:04 -0700 (PDT) jongiddy wrote: > On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote: > > > > Also it doesn't sit well with Python's "one obvious > > way to do it" guideline, because it means there are > > *two* equally obvious ways to call a function. >

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
Hello, On Sun, 8 Jun 2014 01:15:43 -0700 (PDT) jongiddy wrote: > Thanks for the extensive feedback. Here's my thoughts on how to > address these issues. > > On Saturday, 7 June 2014 20:20:48 UTC+1, Ian wrote: > > > > It's a nice feature in a statically typed language, but I'm not sure > > ho

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote: > > Also it doesn't sit well with Python's "one obvious > way to do it" guideline, because it means there are > *two* equally obvious ways to call a function. Actually, one of the best arguments against introducing UFCS is that Python

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote: > > Also it doesn't sit well with Python's "one obvious > way to do it" guideline, because it means there are > *two* equally obvious ways to call a function. This provides a way to do something new (add class-optimized implementations

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
Thanks for the extensive feedback. Here's my thoughts on how to address these issues. On Saturday, 7 June 2014 20:20:48 UTC+1, Ian wrote: > > It's a nice feature in a statically typed language, but I'm not sure > how well it would work in a language as dynamic as Python. There are > some ques

Re: Uniform Function Call Syntax (UFCS)

2014-06-07 Thread Gregory Ewing
Ian Kelly wrote: It's a nice feature in a statically typed language, but I'm not sure how well it would work in a language as dynamic as Python. Also it doesn't sit well with Python's "one obvious way to do it" guideline, because it means there are *two* equally obvious ways to call a function

Re: Uniform Function Call Syntax (UFCS)

2014-06-07 Thread Ian Kelly
On Sat, Jun 7, 2014 at 12:45 AM, jongiddy wrote: > The language D has a feature called Uniform Function Call Syntax, which > allows instance methods to be resolved using function calls. > > In Python terms, the call: > > x.len() > > would first check if 'x' has a method 'len', and would then look