I didn't know what is apparently the ISO notation
(<http://en.wikipedia.org/wiki/Interval_(mathematics)>); I was familiar
with the "set builder notation":
[1,200] would find 1<=x<=200
(1,200) would find 1<x<200
[1,200) would find 1<=x<200
The "]a,b[" example looked contra-intuitive to me; some could read it as
"<= a or >= b". Thus, the mathematical notation might not be the best
solution; it doesn't conform with the Python notation anyway:
range(1,200)
or
[1:200] # Python
is like
[1,200[ # ISO
[1,200) # set builder
or
[1,199] # both ISO and set builder
What about accepting input like this:
1 <= x <= 200 # Python; accept any identifier
>=1 and <=200 # pythonic/english "and"
>=1 && <=200 # C, Bash, DOS-Shell
1 < x < 200 # Python; accept any identifier
>1 and <200 # pythonic "and"
>1 && <200 # C, Bash, DOS-Shell
1 <= x < 200 # Python; accept any identifier
>=1 and <200 # pythonic "and"
>=1 && <200 # C, Bash, DOS-Shell
We could create a callable object when parsing a non-empty expression.
The concept could be extended to evaluate parentheses and even field
names (for a one-entryfield search function). The comma could be
interpreted as "and".
We could generate boolean functions (accepting a single number) or,
perhaps better, SQL code (for the WHERE clause).
The expression syntax would be a superset of Daniel's solution :-) |