riff icon indicating copy to clipboard operation
riff copied to clipboard

Membership expressions

Open darrylabbate opened this issue 2 years ago • 2 comments

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 &&

darrylabbate avatar Oct 31 '22 08:10 darrylabbate

Type dispatch:

  • If y in the expression x 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 value x (not key) is somewhere in the table.
  • If y is a range, assert x 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.

darrylabbate avatar Nov 27 '22 04:11 darrylabbate

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.

darrylabbate avatar Dec 05 '22 10:12 darrylabbate