On Tue, Mar 17, 2020 at 06:12:56PM +0000, haael wrote: > > Python has more and more optional tools for formal correctness cheking.
Are you talking about third-party applications? > Why not loop invariants? Wrong question :-) Adding new language features to Python isn't "default allow", adding every new feature that somebody suggests unless there is a reason not to add it. It is "default deny" -- new features have to be justified before they will be added, and even if they are justified, they still might not be added if: - the costs of the new feature outweigh the benefit; - there is sufficient opposition and insufficient support; - or nobody is interested enough to do the work. So the better question is: *Why add loop invariants as a language feature requiring a new keyword?* > Loop invariant is such a statement that if it was true before the loop > iteration, it will also be true after the iteration. It can be > implemented as an assertion of an implication. > > > now_value = False > while running_condition(...): > prev_value = now_value > now_value = invariant_condition(...) > assert now_value if prev_value else True > > > Here for ellipsis we can substitute any values and variables. An actual real-world example would be more convincing. > I propose the new syntax: > > while running_condition(...): > invariant invariant_condition(...) > > > The keyword 'invariant' is allowed only inside a loop. There are other kinds of invariants than just loop invariants. Can you justify why loop invariants are more important than other invariants? Can you point to other languages that offer loop invariants, but not other invariants or contracts such as preconditions and postconditions? For comparisons sake, this is how Eiffel handles loop invariants: https://www.eiffel.org/doc/eiffel/ET-_Instructions#Loop_invariants_and_variants -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SJ7PHT3SZPQL3DZTNBANA5K4XKG6N3OK/ Code of Conduct: http://python.org/psf/codeofconduct/