[Python-ideas] Inline assignments using "given" clauses
Cameron Simpson
cs at cskk.id.au
Sun May 13 17:13:02 EDT 2018
On 14May2018 02:04, Steven D'Aprano <steve at pearwood.info> wrote:
>"Outer parentheses" is a red herring. I should have written:
>
> (x + x) given x = 50 # this ought to return 100
> x + (x given x = 50) # this ought to return 51
>
>and now there are no outer parentheses to worry about. The question is
>now whether "given" binds more tightly than + or not.
Just to this: as a general principle I think "words" should bind less tightly
than "punctuationlike operators".
Certainly for myself I read most code as "words surrounding expressions". While
"given" and "for (comprehension)" and so forth are all words within expressions
as far as the language grammar goes, to my intuition and _visually_ they are
bulky separators between terse "mathy" things. Even the Boolean words "and",
"or", "not"...) fit this role.
So as a matter of egonomic design "given" ought also to bind less tightly than
"+". Arithmetic before logic before declaration before control, if you like.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-ideas
mailing list