Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-28 Thread Greg Ewing
James Lu wrote: as expr [do comma-separated-expressions]: >block means evaluate expr, then call the result of the expression. If do is present, call it with the argument list after do. This kind of thing has been proposed before. Although it seems like a straightforward idea, there are s

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-28 Thread Jonathan Fine
Hi James This is an attempt to respond to the issues that be lying behind your request for code blocks in Python. It's my two cents worth (https://en.wikipedia.org/wiki/My_two_cents) of opinion. I really do wish we could have language that had all of Ruby's strengths, and also all of Python's. Th

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-28 Thread James Lu
By passing a function to another function I meant passing a code block as an inline function to a function call. The do statement is simply the arguments the function is called with Brackets = optional as expr [do comma-separated-expressions]: block means evaluate expr, then call the result

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Steven D'Aprano
I *think* you are trying to find a syntax for "code blocks" like Ruby has, but I'm not sure. Your examples are a little confusing to me (possibly because you have at least three separate suggestions here, "as" blocks, a mysterious "do" keyword I don't understand, and partial application using %

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 02:07:07PM +0200, Michel Desmoulin wrote: > 4 - introducing a new keyword is the hardest thing you can ever ask on > this list. Introducing a new keyword is like falling off a log compared to introducing a new operator. -- Steve _

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Robert Vanden Eynde
> lumberjack(15, %) > # is equivalent to the expression > lambda x: lumberjack(15, %) You mean lambda x: lumberjack(15, x) ? So you'd want a better syntax for functools.partial, here your example is partial(lumberjack, 15). However this syntax you allow to write lumberjack(%, 15) which is only p

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Michel Desmoulin
I like the concept, and I several times wished I could have had a reference to the block of code in a `with` clause. However, it is unlikely to happen: 1 - Guido restricted lambda to one expression, and this would just be a way around that 2 - This will be tempting to use for callbacks and chain

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Rhodri James
On 25/07/18 18:07, James Lu wrote: I'm open to any changes or criticism. ``` import atexit as atexit.register: # ...do various cleanup tasks... print('Goodbye') # is approximately equivalent to => import atexit def _(): # ...do various cleanup tasks... print('Goodbye') atexi

[Python-ideas] As-do statements/anonymous blocks in python

2018-07-25 Thread James Lu
I'm open to any changes or criticism. ``` import atexit as atexit.register: # ...do various cleanup tasks... print('Goodbye') # is approximately equivalent to => import atexit def _(): # ...do various cleanup tasks... print('Goodbye') atexit.register(_) # flask example @app.route