You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
leads to cleaner / leaner / more orthogonal and composable API's
eg: ospaths.searchExtPos wouldn't be needed with splitExt ; a ton more examples
syntax and semantics
Should follow semantics of D dynamic arrays, cf https://dlang.org/spec/arrays.html ; only difference is that the nim GC is thread-local unlike D's GC
Conceptually, a slice is:
type slice*[T] =object#TODO: slice or Slice? I prefer Capital for types but we have seq[T]...pointer: prt T #CHECKME
length: int# can have a proc `len` that retrieves this `length`
type T =int# for eglet n =10let a =newSlice[T](n) # allocatesasserttype(a) is slice[T]
let b = a[3..6] # no allocationassert b.ptr== a.ptr+3assert b.len ==4
b[0] =100assert a[3] =100# original slice is affected## create a slice from ptr + len (no allocation)let b2 =initSlice(b.ptr, b.len) #TODO: not sure what's the best syntax hereasserttype(b2) is slice[T]
assert b2 == b # does element-wise comparison#TODO: show .dup, .array, setting .len, assignment
I want to keep openArray and turn it into borrowed array slices. The borrowing aspect is hard to achieve with a concept. The better way to do it is to simply patch the stdlib to use a concept where it makes sense
not first class citizen, cf ICE's and bugs with openarray #8259 : some issues are fixable but some seem less so, eg: "Error: invalid type: 'openarray[int]' for var"
can't be defined from arbitrary pointer (eg provided by a C foreign function call)
How to accomodate slice in standard library?
The value of that would be ability to make standard library work regardless of types (otherwise a large number of standard library features may not be available to slices);
Could Nim seq be implemented in terms of slice?
Maybe impossible, because would break too many programs, eg assignment copies for seq, but not slice
Could Nim string be implemented in terms of slice, as in D?
Maybe impossible, because would break too many programs, eg assignment copies for seq, but not slice
Note: lessons learned from D: auto-decoding is bad, and shouldn't be reproduced in Nim
timotheecour
changed the title
[WIP] nim needs a slice type analag to D's T[] array
[WIP] nim needs a slice type analag to D's T[] dynamic array
Jul 10, 2018
[Closing until I flesh out more details]
TODO: maybe move to a repo so other can contribute to proposal
motivation
use cases
exists in other languages
leads to cleaner / leaner / more orthogonal and composable API's
ospaths.searchExtPos
wouldn't be needed withsplitExt
; a ton more examplessyntax and semantics
Should follow semantics of D dynamic arrays, cf https://dlang.org/spec/arrays.html ; only difference is that the nim GC is thread-local unlike D's GC
Conceptually, a slice is:
what about
openArray
there's lack of clarity on what openArray is; eg https://github.com/nim-lang/Nim/issues/6528 argues it should be a concept; but others don't, eg:
openArray
is not the same thing asSlice
, it's aconcept
suitable for interfaces, and most analog to D'srandom access range
trait, see https://dlang.org/library/std/range/primitives/is_random_access_range.htmlnot first class citizen, cf ICE's and bugs with openarray #8259 : some issues are fixable but some seem less so, eg: "Error: invalid type: 'openarray[int]' for var"
can't be defined from arbitrary pointer (eg provided by a C foreign function call)
How to accomodate slice in standard library?
The value of that would be ability to make standard library work regardless of types (otherwise a large number of standard library features may not be available to slices);
Could Nim seq be implemented in terms of slice?
Maybe impossible, because would break too many programs, eg assignment copies for seq, but not slice
Could Nim string be implemented in terms of slice, as in D?
Maybe impossible, because would break too many programs, eg assignment copies for seq, but not slice
Note: lessons learned from D: auto-decoding is bad, and shouldn't be reproduced in Nim
related discussions
The text was updated successfully, but these errors were encountered: