ozra / onyx-lang

The Onyx Programming Language
Other
97 stars 5 forks source link

`in` operator #92

Closed ozra closed 8 years ago

ozra commented 8 years ago

I think this should be added, personally I'm very used to this construct. As usual in Onyx, an operator simply maps to a generic function, user definable.

In this case it should obviously map to includes?.

list = ["some", "stuff", "here"]
tup = (13, 47, 9)
some-val = "bar"

if "stuff" in list => say "got stuff"
if 47 in tup => say "got 47"
if some-val in ("bip", "bop", "boo") => say "got 47"

-- corresponds to:
if list.includes? "stuff" => say "got stuff"
if tup.includes? 47 => say "got 47"
if ("bip", "bop", "boo").includes? some-val => say "got 47"
ozra commented 8 years ago

Both in and in? are allowed for a time of trial.

Also: x not in y, x is in y, x isnt in y. I think these will be removed except for the not in which makes code clearer in many cases: if my-char not in AllowedChars => raise hell