Re: "subsequence" type (like Go's "slice")

2020-06-23 Thread snej
> Er, you can slice with toOpenArray, no need for the inRange: var stuff. That isn't enough, because the proc alters the range (that's why `inRange` is a `var`.) It's basically consuming part of the input array, and updates the start of the range so that on return it points to only the unconsume

Re: "subsequence" type (like Go's "slice")

2020-06-23 Thread Araq
> I'm writing code that manipulates portions of seq s, and I keep creating proc > parameter lists that include input: openarray[byte]; inRange: var Slice[int], > and then inside the proc I keep writing stuff like input[inRange.a + i] Er, you can slice with `toOpenArray`, no need for the `inRange

Re: "subsequence" type (like Go's "slice")

2020-06-22 Thread bpr
> There is also openArray. It's currently restricted to parameters due to > memory safety reasons, there is an RFC to extend it. I assume you mean [this](https://github.com/nim-lang/RFCs/issues/178)? What's the status of that and the other [Nim2020](https://github.com/nim-lang/RFCs/milestone/1)

Re: "subsequence" type (like Go's "slice")

2020-06-22 Thread snej
I'm writing code that manipulates portions of `seq``s, and I keep creating proc parameter lists that include ``input: openarray[byte]; inRange: var Slice[int]`, and then inside the proc I keep writing stuff like `input[inRange.a + i]` 😝 I have a large C++ codebase that uses a custom `slice` typ

Re: "subsequence" type (like Go's "slice")

2020-06-22 Thread Araq
There is also `openArray`. It's currently restricted to parameters due to memory safety reasons, there is an RFC to extend it. I personally mostly use integer indexing which is easier to prove correct than non-owning views. Much easier.

"subsequence" type (like Go's "slice")

2020-06-22 Thread snej
As I get more fluent in Nim, the main tool I find myself missing is a lightweight reference to a range of bytes in memory — something that points to a portion of a `seq` without copying it. The closest equivalent I know of is Go's `slice[T]`, which is pretty ubiquitous — it's actually rare in Go