top | item 43123687

(no title)

jcmoyer | 1 year ago

> logical operators do not short-circuit (so both sides of an or will execute even if the left side is true)

There are two syntaxes: `and` which doesn't short circuit, and `and then` which does. Ditto for `or` and `or else`.

discuss

order

int_19h|1 year ago

Coincidentally, this is the same as C and C++: you have & and && and then you have | and ||. We think of & and | as something that's only useful for bit twiddling, but when you apply them to boolean values, the semantics are exactly that of a non-short-circuiting boolean operator.

bonzini|1 year ago

Interestingly Rust uses the same convention for some methods: Option has "and_then", "or_else", and also a distinction between "unwrap_or" and "unwrap_or_else".

caspper69|1 year ago

Thanks for the heads up.