[Python-ideas] Inline assignments using "given" clauses
Steven D'Aprano
steve at pearwood.info
Sun May 13 07:23:48 EDT 2018
On Sat, May 12, 2018 at 07:36:33PM -0400, Juancarlo Añez wrote:
> Python already uses "in", which is used in other languages to introduce
> context.
Fortunately, we don't have to come up with syntax that works with other
languages, only Python.
> The statement structure of "with...as" seems desirable
But it's not a statement, its an expression.
> just asking for a word that is not "with" or "given".
How about "antidisestablishmentarianism"? That's unlikely to be used in
many programs, so we could make it a keyword.
*wink*
I jest, of course. But I don't think "with" reads well, and given
doesn't really work for me either *as prose*.
In my experience mathematicians put the given *before* the statement:
Given a, b, c three sides of a triangle, then
Area = sqrt(s*(s-a)*(s-b)*(s-c))
where s = (a + b + c)/2 is the semi-perimeter of the triangle.
For the record, that is almost exactly what I wrote for a student
earlier today, and its not just me, it is very similar to the wording
used on both Wolfram Mathworld and Wikipedia's pages on Heron's Formula.
http://mathworld.wolfram.com/HeronsFormula.html
https://en.wikipedia.org/wiki/Heron%27s_formula
Putting "given" after the expression is backwards.
--
Steve
More information about the Python-ideas
mailing list