alehander92 / gara

MIT License
103 stars 4 forks source link

Set support #8

Open alehander92 opened 6 years ago

alehander92 commented 6 years ago

{'a', 'b', @c, @e}

max 1 capture in a set, is it useful

alehander92 commented 5 years ago

Basically we can have

{'a', 'b', @c} : => a.len == 3 and 'a' in a and 'b' in a and (let c = a - {'a', 'b'}; true)

{'a', 'b', *_} => a.len >= 2 and 'a' in a and 'b' in a

All other kinds of checks are forbidden: as some of them are possible, but they'll lead to slower code.

haltcase commented 5 years ago

@alehander42

a.len >= 2 and 'a' in a and 'b' in a

Make sure to use a.card instead of len for sets. I wish this would be changed to len for consistency but it doesn't seem likely (https://github.com/nim-lang/Nim/issues/7556).

Maybe you could also make use of <= for sets.

let a = {1, 2, 3}
let b = {1, 2}

echo b <= a
# -> true, `b` is a subset of `a`
alehander92 commented 5 years ago

yeah, you're right about card wow, I didn't know of <=, a bit strange, but it look like that IN symbol