Open-ended slices

2020-11-17 Thread doofenstein
instead of nil you could use something like this: type PositiveInf = object NegativeInf = object proc `..`(a: typedesc[NegativeInf], b: int) = discard proc `..`(a: int, b: typedesc[PositiveInf]) = discard which then can be used like this: 0..Posit

Open-ended slices

2020-11-16 Thread pietroppeter
Well it appears that you can define a `[.. ]`: Unfortunately, it seems you are not allowed to define at the same time a `[ ..]`.

Open-ended slices

2020-11-16 Thread snej
Hm, no postfix operators... I'm leaning toward using `nil` for the "alpha/omega" sentinels. (That's more or less how they're already represented internally.) So, `for (key, value) in collection[nil .. "x"]:` or `for (key, value) in collection["a" .. nil]:` (I realize `nil` isn't a valid string

Open-ended slices

2020-11-16 Thread doofenstein
how about `..>=x` for an open range closed to the left?

Open-ended slices

2020-11-16 Thread spip
Like in from alpha to omega? `alpha .. X` is bottom-opened range while `Y .. omega` is top-opened range!;-)

Open-ended slices

2020-11-16 Thread b3liever
There are no postfix operators in Nim, with the export marker `*` being a special case. `..X` is defined in system. But for the other case you will need to maybe define a sentinel value that represents the upper limit and use the binary `..` op.

Open-ended slices

2020-11-16 Thread snej
I'm implementing a database cursor class. The keys are basically strings. A cursor can be restricted to a sub-range of the keys, like you might want to iterate only from "X" to "Y". I thought of using subscripts with ".." for this, so `curs["X".."Y"]` would return a copy of `curs` that's restri