Journal of my investigation into the development of a new programming language
Ranges
There are lots of ways to ask questions about ranges:
(1, 5) contains x?
x is_in (1, 5)
Today I was looking at some C code and saw this common pattern:
1 < x && x < 5
And, really, the natural way to represent this would be:
1 < x < 5
But that doesn't work in any language I'm familiar with, because their logic is more machine-focussed. The result of operator < from the right expression would be passed to the first operator and therefore compared with 1. Or it just wouldn't be allowed.
I'd like a language that supported this syntax. It's inconsistent, looked at in conventional ways - because it's not generally meaningful:
1 < 3 > 4 == 2 >= 7
But we are inconsistent, and our natural languages reflect that. I think I'd like a programming language that did, too. There are - there must be - limits to this, and there are undoubtedly implementation problems. Problems, too, of ambiguity - too much idiosyncracy heads in the direction of unreadable code. I'm interested in exploring those boundaries, and I think I'd probably put
1 < x < 3
or even
1 < x <= 3
on the side of good.