Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-16 Thread roger peppe
I agree that rand.Shuffle could have used an interface type that's a subset of sort.Interface. I'm not sure why it didn't, although of course it's easy to go from one to the other: func main() { x := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} xi := sort.IntSlice(x)

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Dan Kortschak
¡left off the Len method! type Swapper interface { // Swap swaps the elements i and j. Swap(i, j int) // Len returns the number of elements that may be swapped. Len() int } func Shuffle(s Swapper) On Tue, 2018-10-16 at 03:46 +, Dan Kortschak wrote: > type Swapper interface { > // Swap

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Bakul Shah
On Mon, 15 Oct 2018 21:29:07 -0600 andrey mirtchovski wrote: > > Unlikely :-) > > > > The following is much less obscure. > > > > func Shuffle(slice inteface{}) > > > > & might have more more sense. e.g. > > > > var cards []card > > ... > > rand.Shuffle(cards) > >

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Dan Kortschak
type Swapper interface { // Swap swaps the elements i and j. Swap(i, j int) } func Shuffle(s Swapper) On Mon, 2018-10-15 at 19:58 -0700, Bakul Shah wrote: > On Mon, 15 Oct 2018 20:39:11 -0600 andrey mirtchovski ail.com> wrote: > > > > > > > > May be it ought to be called FYShuffle? > > then

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread andrey mirtchovski
> Unlikely :-) > > The following is much less obscure. > > func Shuffle(slice inteface{}) > > & might have more more sense. e.g. > > var cards []card > ... > rand.Shuffle(cards) you've now restricted Shuffle to "shuffling" only slices. and it has to examine interface{}

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread 1955neilh
Oh well! Bakul - thank you for that little bit of affirmation. I feel better now :-) > The current Shuffle is confusing. May be because it has a somewhat clumsy interface. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Bakul Shah
On Mon, 15 Oct 2018 20:39:11 -0600 andrey mirtchovski wrote: > > May be it ought to be called FYShuffle? > > then we'ld have to rename it if we switched the algorithm (which has > happened once for sort.Sort already). that's not what go is about :) Unlikely :-) The following is much less

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread andrey mirtchovski
> May be it ought to be called FYShuffle? then we'ld have to rename it if we switched the algorithm (which has happened once for sort.Sort already). that's not what go is about :) maybe you're advocating for implementing a Shuffle interface, which brings us round about to where we are right now

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Bakul Shah
On Oct 15, 2018, at 6:44 PM, Neil Higgins <1955ne...@gmail.com> wrote: > > Ok, Dan. With what you have told me, I acknowledge that shuffling is what > it’s all about, so the metaphysics matches the physics on this case. So the > problem is on my side: Probably a deficit in fluency with

Re: [go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread Jan Mercl
On Mon, Oct 15, 2018 at 4:06 PM <1955ne...@gmail.com> wrote: > Issues (for me): > > Shuffle doesn't seem to swap anything (the thing you want shuffled isn't even an argument) It shuffle things by calling the function literal passed to rand.Shufle. Above it is `func(i, j int) { words[i], words[j]

[go-nuts] Understanding the doc (why can't I?)

2018-10-15 Thread 1955neilh
*Here's the doc for shuffle in math/random*: func Shuffle(n int , swap func(i, j int )) Shuffle pseudo-randomizes the order of elements using the default Source. n is the number of elements. Shuffle panics if n < 0. swap