I have a faint memory of being able to write an if statement in some language like this:
if (foobar == ('this' || 'that'))
Instead of:
if (foobar == 'this' || foobar == 'that')
The latter is more verbose, and therefore less aesthetically appealing to me.
Is the former convention supported in any major languages? Is there a reason why this isn’t widely supported?
The Icon programming language has this feature.
Through the use of generators, you can do
which succeeds if i = 0 or i = 1. You can even do:
which succeeds if any of i, j, or k is equal to 0 or 1.
The basic idea behind this is that each of those
(1|2|3..)sequences creates a generator that will return each of the values in turn until it runs out of values. When you use a generator in a boolean sitation like this, values will be requested from the generator until the comparison succeeds. When you combine two generators on either side of the comparison, all the possible combinations will be attempted until one succeeds. (Instead of return false, the equality operator ‘fails’ if the values are not equal.)