On Thu, Jan 31, 2013 at 3:27 AM, Dan Kortschak wrote:
Why is it not possible to reflect.Value.Slice() on an unaddressable array? This undoubtedly going to simple, but I don't understand it.http://play.golang.org/p/23gm1OIAWp
A slice gives you another view into an existing array. When you
reflect on array by value, you are passing in a copy of the array
value, not the address of the array. A slice of that copy will give
you another view into that copy. This is a confusing notion: you've
got a slice of an array, but you don't have the array itself. You're
right that it could be implemented, but the result is potentially
In any case the reflection rules simply restate the language rules.
You can not take a slice of an unaddressable value in the language
And I guess a related question which will probably answer the first, 'What exactly is an addressable array?' It isn't clearly defined in the reflect documentation (and the restriction on Slice isn't noted except in the source), and though I have seen arrays that are addressable by virtue of the fact that they can be .Sliced, but I can't see what makes them different (a pointer to an array can not be sliced as it is not an array).
The definition of addressable is in the language spec:http://golang.org/ref/spec#Address_operators
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/groups/opt_out.