gop icon indicating copy to clipboard operation
gop copied to clipboard

`start:end:step`

Open xushiwei opened this issue 4 years ago • 4 comments

a[start:end:step] = value

for i <- start:end:step {
    ...
}

for i := range start:end:step {
    ...
}

for range start:end:step {
    ...
}

for start:end:step {
    ...
}

xushiwei avatar Aug 28 '21 06:08 xushiwei

It's awkward that there is a slice syntax a[start:end:cap] in Go. However, if a is not a slice or array type, we still can use a[start:end:step].

Or usestart:end by step?

a[start:end by step] = value

for i <- start:end by step {
    ...
}

for i := range start:end by step {
    ...
}

xushiwei avatar Aug 28 '21 06:08 xushiwei

julia & matlab:

start:step:end

xushiwei avatar Aug 28 '21 06:08 xushiwei

type Matrix[T Numeric] struct ...

func (m *Matrix[T]) [] (i, j int) T { // getter: x = m[i, j] translates to x = m.[](i, j)
}

func (m *Matrix[T]) []= (i, j int, x T) { // setter: m[i, j] = x translates to m.[]=(i, j, x)
}

From https://medium.com/@rhadar/a-data-scientists-take-on-go-ed408c00ac45, https://github.com/golang/go/issues/41129

xushiwei avatar Oct 28 '21 05:10 xushiwei

Only implement for range in milestone v1.1

  • https://github.com/goplus/gop/issues/865

xushiwei avatar Nov 05 '21 16:11 xushiwei