grain-lang / grain

The Grain compiler toolchain and CLI. Home of the modern web staple. 🌾
https://grain-lang.org/
GNU Lesser General Public License v3.0
3.25k stars 114 forks source link

Stdlib: Improve Array.contains with recursion #189

Open phated opened 4 years ago

phated commented 4 years ago

When we can pattern match on arrays, we need to rewrite Array.contains with recursion instead of a while-loop.

Ref #188

clovis1122 commented 3 years ago

I'll tackle this one!

ospencer commented 3 years ago

We're not quite ready for this one since we don't yet have pattern matching on arrays. My bad for mislabeling this one!

phated commented 3 years ago

@ospencer I believe you said that we still can't implement recursion with array pattern matches because we don't support ...rest-style pattern matches, is that correct? Should I create another issue for this to be blocked upon?

ospencer commented 3 years ago

That's correct. In that issue, we should probably discuss if we want to support ...rest for Arrays since it requires us to copy array[1:] on each iteration (not that we couldn't, but it would be really inefficient).

peblair commented 3 years ago

That's correct. In that issue, we should probably discuss if we want to support ...rest for Arrays since it requires us to copy array[1:] on each iteration (not that we couldn't, but it would be really inefficient).

Perhaps that could be supported by adding a layer of indirection in front of arrays? Then, when doing a slice, we just return a new view of the same underlying array? (cross-posting to #490)