riff
riff copied to clipboard
Membership expressions
Currently, in
is only supported in for
loops. in
can be added as an infix operator (membership, pattern matching, etc); valid in any expression. Support for not in
would need to be implemented as well.
Precedence level should be lower than ~
and ..
but higher than &&
Type dispatch:
- If
y
in the expressionx in y
can be coerced to string,x in y
should essentially be the inverse of pattern matching (i.e.y ~ x
). - If
y
is a table,x in y
evaluates as true if the valuex
(not key) is somewhere in the table. - If
y
is a range, assertx
is an integer (or float equivalent) and falls in the range. I.e.x in a..b:c
== $\lbrace x|x\in c\mathbb{Z}, a \leqslant x \leqslant b \rbrace$
For all other types, it should follow whatever rules the pattern matching operation enforces.
Precedence level should be lower than
~
and..
but higher than&&
Not currently possible to be lower than ..
but also higher than &&
. Logical operators should probably be lowered s.t. a in b..c && x in y..z
does what you'd expect. ..
was originally given very low precedence since its only real uses were for
loops and substring extraction.