Using a struct
type Heap struct {
items []Item
}
func (h *Heap) Pop() interface{} { ... }
func (h *Heap) Push(x interface{}) { ... }
lets you use the more legible (to me, anyway)
h.items[i]
Jonathan
--
You received this message because you are subscribed to the Google Groups
"golang-nut
There are cases when using a pointer to a slice is both natural and
correct. For example, when using the container/heap package, I often write
code similar to
type Heap []Item
func (h *Heap) Pop() interface{} { ... }
func (h *Heap) Push(x interface{}) { ... }
Here, "func (h Heap) ..." would be in
A pointer to an array is useful. A pointer to a slice is much less so; in
fact, it's often a mistake. The slice already contains a pointer to the
data (in fact, as a pointer to an array!). Best not to promote the bad idea.
-rob
On Sun, Dec 4, 2016 at 11:27 AM, Patrick Smith wrote:
> The spec s
The spec says:
"A primary expression of the form
a[x]
denotes the element of the array, pointer to array, slice, string or map a
indexed by x."
I am curious about one point - what is the reason for allowing a to be a
pointer to array, but not allowing a to be a pointer to slice? In both
case