Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'syntax': 0.04; 'importing': 0.05; 'attribute': 0.07; 'practice,': 0.07; 'string': 0.09; 'ambiguity': 0.09; 'parameter': 0.09; 'sake': 0.09; 'subject:Function': 0.09; 'used.': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; '2),': 0.16; 'argument.': 0.16; 'bitwise': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'least.': 0.16; 'massively': 0.16; 'namespace.': 0.16; 'notation': 0.16; 'partly': 0.16; 'positional': 0.16; 'syntactic': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'pipe': 0.31; 'skip:r 60': 0.31; 'steven': 0.31; 'though.': 0.31; '"the': 0.34; 'maybe': 0.34; 'could': 0.34; 'subject: (': 0.35; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'really': 0.36; 'skip:s 60': 0.36; 'useful': 0.36; 'clear': 0.37; 'needed': 0.38; 'pm,': 0.38; 'bad': 0.39; 'itself': 0.39; 'though,': 0.39; 'sure': 0.39; 'how': 0.40; 'even': 0.60; 'middle': 0.60; 'solve': 0.60; 'first': 0.61; 'name': 0.63; 'such': 0.63; 'become': 0.64; 'different': 0.65; 'talking': 0.65; 'here': 0.66; "it'd": 0.84; 'pike': 0.84; 'absolutely': 0.87; 'pipeline': 0.91; 'to:none': 0.92; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=haUtsWR4W17BIRL3vL15wVOcfHB00WDnd6ktzd2MGhQ=; b=burAXLteaC5zbXXnQ+0SP2uElmfzdiofwxN/mbj3bvNOSlNN9Qrl9I2kJeL3mmgdCy ATy+BNbyPObsSgBN84PRZ9s7bNheWwKrlyvU+P8FNZv8Y0BrQ4M8f5XjTToMyTEkFwAa ZasCcly+tq/pCkWwu6gaFtRX8/PLJTp4WY7eCYHpHprEzzTeqr8Lz41ZGC+fF4EmInzL gaDZcRIeV+nrvmBJrcoSxIG9bt2RLPtC963760PyrHK6HTbutm3b42HaJyTlHWqgn1LY w3U6NF8VabDpQDSPhmOoVM9i3l8vrY1HmhnTCe4q7XovRY149CyAEVuquJicYrXesTXy +r3w== MIME-Version: 1.0 X-Received: by 10.58.229.101 with SMTP id sp5mr21492427vec.42.1402285463074; Sun, 08 Jun 2014 20:44:23 -0700 (PDT) In-Reply-To: <53952807$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <8b96ae27-20fa-4df9-807e-c806fed983c0@googlegroups.com> <38058e64-0113-457c-ae63-cc66e8b569cd@googlegroups.com> <12d31393-3598-4304-8ce9-ac847ac21c64@googlegroups.com> <53952807$0$29988$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 9 Jun 2014 13:44:22 +1000 Subject: Re: Uniform Function Call Syntax (UFCS) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402285465 news.xs4all.nl 2890 [2001:888:2000:d::a6]:51732 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73001 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 data flow: >> >> read_file("foo.jpg").JPEG_decode().autocrop().rotate(0.5).grey() >> .PNG_encode().write_file("foo.png"); >> >> I had to solve the syntactic ambiguity here by importing all the >> appropriate names > > I'm not sure how this is *syntactic* ambiguity. The ambiguity I'm talking about here is with the dot. The original version has "Stdio.read_file" as the first function called; for a Python equivalent, imagine a string processing pipeline and having "re.sub" in the middle of it. You can't take "re.sub" as the name of an attribute on a string without some fiddling around that completely destroys the point of data-flow syntax. So I cheated, and turned everything into local (imported) names (adorning the ones that needed it). This is a bad idea in Pike for the same reason it's a bad idea in Python - you end up with a massively polluted global namespace. 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) | divide(2) This would be absolutely identical to: divide(plus(1, 2), 2) Maybe you could even make it so that: plus(1, 2) x=| divide(y=2) is equivalent to divide(x=plus(1, 2), y=2) for the sake of consistency, and to allow the pipeline to inject something someplace other than the first argument. I'm not sure whether it'd be as useful in practice, though. It would depend partly on the exact syntax used. Obviously the pipe itself can't be used as it already means bitwise or, and this needs to be really REALLY clear about what's going on. But a data-flow notation would be of value in theory, at least. ChrisA