Array indexing and slice syntax #387
LightAndLight
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Indexing
I currently use
array.getto access array elements. It's partial, and I've suggested total and partial versions in #386 (getandget!).I might want array indexing syntax that desugars to
get!. I like using.for projection, so I was thinking something likex.1,x.(1), orx.[1].Array indexing in other languages often uses brackets (
x[1]), and arrays already use brackets ([1, 2, 3]), so of the three options above I preferx.[1].Slicing
Once we have an indexing syntax, I'd like slice syntax. Something like
x.[a..b]orx.[a:b]. I prefer offset/length slicing rather than start/end(inclusive/exclusive) slicing. So I favourx.[a:b]overx.[a..b]; to me..seems to lend itself better to the start/end style. The only problem withx.[a:b]is that:already means "has type", and I'd prefer to keep it that way. Perhaps;instead? How does that fit with #210? What about a plain,?:x.[1:2]- create a sub-array of length 2 starting from index 1x.[3:]- create a sub-array of lengtharray.length x - 3(include all remaining elements) starting from index 3;x.[1; 2]x.[3;]Kinda icky
,x.[1, 2]x.[3,]Yeah, no.
Other languages
Wikipedia article: https://en.wikipedia.org/wiki/Array_slicing
Language comparison: https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Slicing
Beta Was this translation helpful? Give feedback.
All reactions