Steve,

I've seen *unless* discussed and rejected before, but it is a good enough
syntax for the purpose of asserting invariants, and it should be useful for
other purposes (because it has been proposed before).

The semantics are clear, and the implementation is simple with the new
Python parser shortcutting to an "*if not"*.

I do really like this option.


On Sun, Sep 12, 2021 at 1:46 AM Steven D'Aprano <st...@pearwood.info> wrote:

> On Sat, Sep 11, 2021 at 02:30:10PM -0400, Juancarlo Añez wrote:
>
> > *invariant* cond: etc
>
> A software invariant is still an assertion.
>
> In another post, I semi-suggested a new (soft) keyword:
>
>     unless condition:
>         # block
>         raise Exception
>
> But really, it's just an "if not".
>
>     if not condition:
>     unless condition:
>     assert condition:
>
> are all exactly the same amount of typing. It's not clear that learning
> a new keyword `unless` is more readable than just using `if not`.
>
> I think it might work better in languages that attempt to follow natural
> language (e.g. XTalk languages) than one like Python with a relatively
> minimal amount of syntax. But it is clear to me that using `assert` for
> non-assertions is misleading.
>
> --
> Steve
> _______________________________________________
> 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/ERBJUTXNAVALGUGDPC7EHQT3LUP3NQHB/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Juancarlo *Añez*
_______________________________________________
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/3GOYGFSNKEGVB2NFC6MT5C2U7KNS3UEG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to