[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Rob Cliffe via Python-ideas
When can we expect the results of your survey?  (I responded to it.) Best wishes Rob Cliffe On 17/07/2023 21:41, Dom Grigonis wrote: Hi everyone, I am not very keen on long discussions on such matter as I do not think there is much to discuss: there is no technical complexity in it and it doe

[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Chris Angelico
On Sat, 5 Aug 2023 at 22:49, Dom Grigonis wrote: > 3. The Python syntax is easily understandable to anyone who knows English as > it follows English syntax: "What are you doing tonight?" "I'm going to the > movies, if I manage to leave work on time, otherwise I'll just stay home.” > * Is the e

[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Dom Grigonis
Ok. > On 5 Aug 2023, at 16:02, Chris Angelico wrote: > > On Sat, 5 Aug 2023 at 22:49, Dom Grigonis wrote: >> 9. Python has a syntax for conditional expressions. Learn it, if you want to >> use Python. No need to create multiple syntaxes for the same thing. >> * Hello Chris A? :) > > Nope. >

[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Chris Angelico
On Sat, 5 Aug 2023 at 22:49, Dom Grigonis wrote: > 9. Python has a syntax for conditional expressions. Learn it, if you want to > use Python. No need to create multiple syntaxes for the same thing. > * Hello Chris A? :) Nope. ChrisA ___ Python-ideas

[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Dom Grigonis
Thank you for reminding Rob. Results are not surprising. Although 10 years ago people preferred C-style, by this time everyone is used to python’s expression. By this time, after having discussions, I myself, am not a proponent of such change. It was more about possibility of having 2 condition

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-21 Thread Chris Angelico
On Fri, 21 Jul 2023 at 19:58, Dom Grigonis wrote: > > Did not mean that it is easy, but it seems achievable and although a deep dig > might be needed, my gut feeling is that it is possible to achieve this fairly > elegantly. I might be wrong ofc. > Start on that deep dig, then, and figure out w

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-21 Thread Dom Grigonis
Did not mean that it is easy, but it seems achievable and although a deep dig might be needed, my gut feeling is that it is possible to achieve this fairly elegantly. I might be wrong ofc. However, this seems orthogonal to everything else I wrote. Just added it for the sake of completeness, thi

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-21 Thread Chris Angelico
On Fri, 21 Jul 2023 at 19:15, Dom Grigonis wrote: > However, it could be done differently as well. If `Break()` takes effect in > the scope where it is evaluated. Then: > You say that as if it's easy. How would this work? How do you have a function that, when called, causes the current loop to b

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-21 Thread Dom Grigonis
Having said that, What about a mid-ground approach? Simply have a `deferred` type, which only gets evaluated if it is explicitly asked for. It builds a graph in the same way as dask, but it does not act as a proxy, but rather evaluates if explicitly asked. From technical perspective, it would

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-21 Thread Dom Grigonis
This is very much implementation dependent. And I do not have a big opinion here as I certainly haven’t spent enough time to have one. I am just considering functionality from user’s perspective for the time being. > Let's tackle just this one part for a moment. What does "ensure_eval" > do? Eva

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-20 Thread Chris Angelico
On Fri, 21 Jul 2023 at 11:08, Dom Grigonis wrote: > Also, can't find a way to ONLY force evaluation without any additional > operations in this specific library. A simple callable which evaluates if > unevaluated & returns would do. Then: > > def IF(condition, when_true, when_false): > if co

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-20 Thread Dom Grigonis
That is where I got to really. Ability to construct one’s own expressions, where evaluation can be controlled. And found out that deferred evaluation is what would potentially provide exactly what is needed for this. Making use of ‘function’ protocol seems appropriate as I don’t think inventing

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-20 Thread Chris Angelico
On Fri, 21 Jul 2023 at 05:53, Random832 wrote: > > On Mon, Jul 17, 2023, at 16:41, Dom Grigonis wrote: > > Would be interesting to see if my preference is an outlier or not really. > > I think this is a false dichotomy. We should consider VB-like conditional > expressions if(condition, when_true,

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-20 Thread Random832
On Mon, Jul 17, 2023, at 16:41, Dom Grigonis wrote: > Would be interesting to see if my preference is an outlier or not really. I think this is a false dichotomy. We should consider VB-like conditional expressions if(condition, when_true, when_false) as well. _

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Chris Angelico
On Wed, 19 Jul 2023 at 11:51, Dom Grigonis wrote: > > Coming back to deferred evaluation, > > https://peps.python.org/pep-0671/ > These 2 aren’t really orthogonal in functionality. Maybe in implementation. > But PEP671 is a certain subset of deferred evaluation as it can achieve the > same with 1

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Dom Grigonis
Coming back to deferred evaluation, https://peps.python.org/pep-0671/ These 2 aren’t really orthogonal in functionality. Maybe in implementation. But PEP671 is a certain subset of deferred evaluation as it can achieve the same with 1 extra line at the start of

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Richard Damon
On 7/18/23 12:03 AM, Dom Grigonis wrote: Ok, thanks. I think what I am aiming at is that there is a pool of suggestions and PEPs that are pointing towards very similar direction and I find myself often wandering in the same space, just trying to figure out what it exactly is. It sometimes fee

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Chris Angelico
On Tue, 18 Jul 2023 at 19:02, Dom Grigonis wrote: > > Thank you. > > I meant “superset of 671, not 505”… > > One question: > > def bar(a => None); > return foo(a) > > def foo(a => object()): > return a > > How would I force foo’s default from bar’s call? That's a known-hard problem. The b

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Dom Grigonis
Thank you. I meant “superset of 671, not 505”… One question: def bar(a => None); return foo(a) def foo(a => object()): return a How would I force foo’s default from bar’s call? Would something like this work? def foo(a => object() if a is None else a): return a > On 18 Jul 2023, a

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-18 Thread Dom Grigonis
Maybe could be a part of https://peps.python.org/pep-0463/ Maybe if it was more expressive, e.g. covering the case such as you suggesting, it would go through? Also, I still don't see why changing analogous statement order when making 1-line expressions is a

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Chris Angelico
On Tue, 18 Jul 2023 at 16:25, Dom Grigonis wrote: > > Yes, thank you, this would definitely be nice to have. > > Although, "A generic system for deferred evaluation has been proposed at > times“ sound better if it was a superset of PEP505. Could you refer me to any > resources about such conside

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Dom Grigonis
Yes, thank you, this would definitely be nice to have. Although, "A generic system for deferred evaluation has been proposed at times“ sound better if it was a superset of PEP505. Could you refer me to any resources about such considered system? > On 18 Jul 2023, at 08:33, Chris Angelico wrote

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread Stephen J. Turnbull
David Mertz, Ph.D. writes: > I think the Python version does the right thing by emphasizing the > DEFAULT by putting it first, and leaving the predicate and fallback > until later in the expression (right for Pythonic code, not right > for other languages necessarily). Aside: I think that's t

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Chris Angelico
On Tue, 18 Jul 2023 at 14:07, Dom Grigonis wrote: > PEP505 would solve this nicely, but it only applies to None and would not > apply to say user-defined sentinels and many other cases where permutations > of different conditionals arise. > PEP 671 would solve this nicely too. ChrisA _

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Dom Grigonis
Ok, thanks. I think what I am aiming at is that there is a pool of suggestions and PEPs that are pointing towards very similar direction and I find myself often wandering in the same space, just trying to figure out what it exactly is. It sometimes feels more verbose than it could be for what it

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Greg Ewing
On 18/07/23 10:30 am, Dom Grigonis wrote: Although, the argument that python is meant to be read as english is very much valid, but I do not see why it has to be an overarching one if the opportunity cost of it is too great in other dimensions. It's not overarching. Many things in Python don't

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Dom Grigonis
Much of what you respond to me indicates that you did not properly read what I have written and did not really understand where I am coming from. > On 18 Jul 2023, at 04:04, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 10:37, Dom Grigonis wrote: >> As opposed to >> >> if a == 0: >> foo,

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Chris Angelico
On Tue, 18 Jul 2023 at 10:37, Dom Grigonis wrote: > As opposed to > > if a == 0: >foo, bar = var1, variable2 > else: >foo, bar = default, default2 > > > Again, one is `a == 0`, another is `b == 0`. I didn’t do a good job conveying > this did I… Will try to be more precise and leave less r

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Dom Grigonis
>> # Code becomes easily read when there is a nice alignment in horizontal >> space. e.g.: >> >> variable = None >> length_1 = None >> somethin = None >> > > variable = length_1 = somethin = None Obviously they would not all be None, just chosen None as `any dummy value`, mistake on my part

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Chris Angelico
On Tue, 18 Jul 2023 at 08:34, Dom Grigonis wrote: > > I still feel that compared to list comprehension and other functional and > elegant python constructs, python's if-else expression is lacking. I often > choose to go multi-line much more verbose code as opposed to more brief > constructs jus

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Dom Grigonis
Ah, I can’t do that post-publish. This will have to suffice for now. If this got to a point where there was a case to revise 2005 decision or introduce an alternative (which I very much doubt can happen any time soon), much more elaborate research and survey would have to be done and all options

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread Dom Grigonis
A bit disappointing, but very much expected. I just though a bit of effort is worth even for 0.1% probability of success. At least from where I stand, such change would make a fairly big impact on the things I do, given my expected relationship with python. I haven’t studied much of a history o

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-17 Thread Laurent Lyaudet
Hello all, Please Dom Grigonis add choices : - "No preference" choice to first question - "I don't know" or "I can't tell" to third question And I will answer to your poll and probably other people will feel and do the same. I agree that question 2 makes me prefer C syntax. But C is not the nicest

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread David Mertz, Ph.D.
I found the original discussion about the ternary addition, FWIW: https://mail.python.org/pipermail/python-dev/2005-September/056846.html. I don't see myself participating in the discussion (maybe it's in a different thread), but I'm delighted to remember that the message Guido posted a couple hou

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread Oleg Broytman
On Tue, Jul 18, 2023 at 07:09:54AM +1000, Chris Angelico wrote: > On Tue, 18 Jul 2023 at 06:43, Dom Grigonis wrote: [skip] > > https://q5yitzu62.supersurvey.com > > Your second example needs a "both are abhorrently unreadable" option. +1 [skip] > ChrisA Oleg. -- Oleg Broytman

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread David Mertz, Ph.D.
This ship has sailed and the ternary operator isn't going to change. Seriously, let it go. I forget the PEP, but this was well discussed long ago when the ternary was added. In general, Python prefers words to punctuation symbols for most of its constructs. So the decision was consistent with th

[Python-ideas] Re: Conditional 1-line expression in python

2023-07-17 Thread Chris Angelico
On Tue, 18 Jul 2023 at 06:43, Dom Grigonis wrote: > > Hi everyone, > > I am not very keen on long discussions on such matter as I do not think there > is much to discuss: there is no technical complexity in it and it doesn’t > really change or introduce anything new. It is only a matter of opini