On Dec 11, 5:38 am, Russ Cox <
r...@golang.org> wrote:
> We spent a long time batting around possible syntaxes
> for that and didn't come up with anything without problems.
> The biggest drawback of the above is that it invites people to
> expect dest[1:3] = src[10:15] to work, but that's a very
> expensive operation.
I don't see any definite operation, which should be done there - like
one might think that it runs through src with step 2 over one element
and might think that if it's float array, it does dest[1]=(src[10]+src
[11])/2 etc, but there is no one specific operation for creating array
longer, it more like depends on the specific type of what's inside.
Additionally, I think it's precisely a case where compiler can give an
error - get this error once and won't excpect it any more. Anyway, if
dest[1:3] = src[10:15:2] to copy over one, this would be nice to have,
because for "nondiscrete" arrays like images and function diagrams
this makes sense to go like that, even src[10:15:1.5] would make sense
and make things lot more beautiful for arrays, which have some kind of
middle operation implemented - like having typeof(src).betweenvalue
(firstelement, secondelement, distance) implemented, which would give
int.betweenvalue(4, 8, 0.5) as 6 ...or if I could directly overload int
[].floatindex for that. Then, to show that this kind of expensive
operation is needed with autocalculated step size, src[10:15:] would
be used to put a checkmark that programmer has read a manual, then src
[10::2] would give the same slice with step.
Also, how it is about arrays of several dimensions in Go? I personally
would like very much to have multidimensional slices like dst[1:4,
3:2] to go through 1,3;2,3;3,3;4,3;1,2;2,2;3,3;4,2 - and I would like
to swap things with giving negative step size etc. This would give
some possibilities to make many typical raster image and also vector
space operations simple. If I could have an interface to provide my
own slice types - knowing that they are slow when I have read manual
enough to implement them.
So if I could create an interface for my own int slice (taking int[]
as parent type) and then using those slices together with other
slices. Such overloaded slice would have some signature in it's name
making it clear that it's overloaded and not a real type - like ()
somewhere.
I personally was a little bit frustrated that I couldn't use complex
number as simulated array's index in python - this matrix code is
example about that, one could not use tuple or complex number as index
neither two comma-separated values to have one index pointer. I
personally think that [1:3, 1:5] and [1:3][1:5] should be both
possible and also using tuple as in [[(1,3), (1:5)]] with [(1,3),
(1:5)] being precalculated. Not with basic types, but in overloaded
types and in such way that one doesn't think accidentially that this
is a fast primitive, even if it might be. I would need [1:3, 1:5] for
structures, which don't split into several arrays (own class); [1:3]
[1:5] when there are arrays inside arrays and [[(1,3), (1:5)]] if I
have precalculated positions to take slices from one or more arrays.
Also, if dst[1:4] is a pointer, then doint reverse(dst[1:4]) should
give dst[4:1:-1] as in python. But getting a chance to overload it
gives nicer and more elegant code, I'm sure, and copy is also an
assign operation, which should look instantly recognizable.
I think that major problem with programming language syntax design is
using human's image processing ability in most effective ways. "Copy"
is distinguishable shape as some typesetting specialist would probably
agree, but I think everyone agrees that "=" is more of that and pretty
definitely more optimized in human brain. Thus this syntax might be
worth of tradeoff of getting some error or warning when trying to do a
slow thing.
> Russ