goplus / gop

The Go+ programming language is designed for engineering, STEM education, and data science. Our vision is to enable everyone to become a builder of the digital world.
https://goplus.org
Apache License 2.0
8.91k stars 546 forks source link

`start:end:step` #764

Open xushiwei opened 3 years ago

xushiwei commented 3 years ago
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 commented 3 years ago

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 commented 3 years ago

julia & matlab:

start:step:end
xushiwei commented 2 years ago
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 commented 2 years ago

Only implement for range in milestone v1.1