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

2018-10-15 Thread Neil Higgins
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 idiomatic code. 

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Dan Kortschak
I'm curious. What name would you suggest?

Note that what I said below applies here; shuffling is what is the
intended use of rand.Shuffle. It could conceivably be used for
alternative things, but then C's sprintf can be used for writing to
arbitrary memory, though that is not what is intended. Should sprintf
be renamed to "writememory"?

ApplyFisherYatesIndexPairsToFunc would be the most accurate (beyond
just making the code be the documentation), but that then depends on
the user knowing that Fisher-Yates is a shuffling mechanism in the
common case, and knowing what Fisher-Yates does in the general case.
The current situation leads someone who's looking to shuffle something
to the function, and then provides two examples to show how that works.

There is obviously some assumed common knowledge, but without that
assumption things become untenable.

On Tue, 2018-10-16 at 10:39 +1000, Neil Higgins wrote:
> I would ascribe metaphysicality to the current name, and
> comprehensibility to a more accurate name. In this case, “shuffling”
> is just an example of what can be done. Abstraction is all very nice,
> until any applied meaning is completely lost in mumbo-jumbo.
>
> Neil Higgins (iPhone)
> higgins-dem...@bigpond.com
>
> >
> > On 16 Oct 2018, at 10:20 am, Dan Kortschak  > edu.au> wrote:
> >
> > But this is not really what it does. You can see from the output of
> > this code https://play.golang.org/p/88Llo7zHTeK
> >
> > ```
> > package main
> >
> > import (
> > "fmt"
> > "math/rand"
> > )
> >
> > func main() {
> > rand.Shuffle(10, func(i, j int) {
> > fmt.Println(i, j)
> > })
> > }
> > ```
> >
> > That `i` is not sampled from a random distribution, but in fact
> > counts
> > down from the last index.
> >
> > This is an implementation of the Fisher-Yates shuffle https://golan
> > g.or
> > g/src/math/rand/rand.go?s=7456:7506#L225
> >
> > The reason that rand.Shuffle is called Shuffle is that that is it's
> > intention. Just as sort.Sort has the intention of sorting things,
> > but
> > needn't necessarily (https://play.golang.org/p/VdMuiFfcp6w).
> >
> > If we want to get metaphysical, nothing that we get the machine
> > todo
> > intrinsically means anything beyond what meaning we ascribe to it
> > (under some transformation or set of bases). This is why we name
> > things
> > and why those names matter.
> >
> > >
> > > On Tue, 2018-10-16 at 08:49 +1000, Neil Higgins wrote:
> > > So as well as getting rid of the euphemistic name, the
> > > documentation
> > > should simply say that it delivers n pairs of random numbers in
> > > the
> > > relevant range to a user-defined function.
> > >
> > > Neil Higgins (iPhone)
> > > higgins-dem...@bigpond.com
> > >
> > > >
> > > >
> > > > On 16 Oct 2018, at 8:31 am, Neil Higgins <1955ne...@gmail.com>
> > > > wrote:
> > > >
> > > > Well, ok. But I would call “Shuffle” a misleading misnomer,
> > > > because
> > > > until the user defines a shuffler function (which perversely
> > > > might
> > > > not, or might fail to, shuffle anything), it does not shuffle
> > > > anything.
> > > >
> > > > Thanks for taking the time to answer my question. Neil

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Neil Higgins
I would ascribe metaphysicality to the current name, and comprehensibility to a 
more accurate name. In this case, “shuffling” is just an example of what can be 
done. Abstraction is all very nice, until any applied meaning is completely 
lost in mumbo-jumbo.

Neil Higgins (iPhone)
higgins-dem...@bigpond.com

> On 16 Oct 2018, at 10:20 am, Dan Kortschak  
> wrote:
> 
> But this is not really what it does. You can see from the output of
> this code https://play.golang.org/p/88Llo7zHTeK
> 
> ```
> package main
> 
> import (
> "fmt"
> "math/rand"
> )
> 
> func main() {
> rand.Shuffle(10, func(i, j int) {
> fmt.Println(i, j)
> })
> }
> ```
> 
> That `i` is not sampled from a random distribution, but in fact counts
> down from the last index.
> 
> This is an implementation of the Fisher-Yates shuffle https://golang.or
> g/src/math/rand/rand.go?s=7456:7506#L225
> 
> The reason that rand.Shuffle is called Shuffle is that that is it's
> intention. Just as sort.Sort has the intention of sorting things, but
> needn't necessarily (https://play.golang.org/p/VdMuiFfcp6w).
> 
> If we want to get metaphysical, nothing that we get the machine todo
> intrinsically means anything beyond what meaning we ascribe to it
> (under some transformation or set of bases). This is why we name things
> and why those names matter.
> 
>> On Tue, 2018-10-16 at 08:49 +1000, Neil Higgins wrote:
>> So as well as getting rid of the euphemistic name, the documentation
>> should simply say that it delivers n pairs of random numbers in the
>> relevant range to a user-defined function.
>> 
>> Neil Higgins (iPhone)
>> higgins-dem...@bigpond.com
>> 
>>> 
>>> On 16 Oct 2018, at 8:31 am, Neil Higgins <1955ne...@gmail.com>
>>> wrote:
>>> 
>>> Well, ok. But I would call “Shuffle” a misleading misnomer, because
>>> until the user defines a shuffler function (which perversely might
>>> not, or might fail to, shuffle anything), it does not shuffle
>>> anything.
>>> 
>>> Thanks for taking the time to answer my question. Neil

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Dan Kortschak
But this is not really what it does. You can see from the output of
this code https://play.golang.org/p/88Llo7zHTeK

```
package main

import (
"fmt"
"math/rand"
)

func main() {
rand.Shuffle(10, func(i, j int) {
fmt.Println(i, j)
})
}
```

That `i` is not sampled from a random distribution, but in fact counts
down from the last index.

This is an implementation of the Fisher-Yates shuffle https://golang.or
g/src/math/rand/rand.go?s=7456:7506#L225

The reason that rand.Shuffle is called Shuffle is that that is it's
intention. Just as sort.Sort has the intention of sorting things, but
needn't necessarily (https://play.golang.org/p/VdMuiFfcp6w).

If we want to get metaphysical, nothing that we get the machine todo
intrinsically means anything beyond what meaning we ascribe to it
(under some transformation or set of bases). This is why we name things
and why those names matter.

On Tue, 2018-10-16 at 08:49 +1000, Neil Higgins wrote:
> So as well as getting rid of the euphemistic name, the documentation
> should simply say that it delivers n pairs of random numbers in the
> relevant range to a user-defined function.
>
> Neil Higgins (iPhone)
> higgins-dem...@bigpond.com
>
> >
> > On 16 Oct 2018, at 8:31 am, Neil Higgins <1955ne...@gmail.com>
> > wrote:
> >
> > Well, ok. But I would call “Shuffle” a misleading misnomer, because
> > until the user defines a shuffler function (which perversely might
> > not, or might fail to, shuffle anything), it does not shuffle
> > anything.
> >
> > Thanks for taking the time to answer my question. Neil

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Neil Higgins
So as well as getting rid of the euphemistic name, the documentation should 
simply say that it delivers n pairs of random numbers in the relevant range to 
a user-defined function. 

Neil Higgins (iPhone)
higgins-dem...@bigpond.com

> On 16 Oct 2018, at 8:31 am, Neil Higgins <1955ne...@gmail.com> wrote:
> 
> Well, ok. But I would call “Shuffle” a misleading misnomer, because until the 
> user defines a shuffler function (which perversely might not, or might fail 
> to, shuffle anything), it does not shuffle anything.
> 
> Thanks for taking the time to answer my question. Neil

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread andrey mirtchovski
> Well, ok. But I would call “Shuffle” a misleading misnomer, because until the 
> user defines a shuffler function (which perversely might not, or might fail 
> to, shuffle anything), it does not shuffle anything.

how would you implement shuffle in golang so that it's not a
misleading misnomer? i would presume that you would give Shuffle a
slice and expect it to return it shuffled? but then if the slice is
empty, Shuffle has still not shuffled anything :)

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Neil Higgins
Well, ok. But I would call “Shuffle” a misleading misnomer, because until the 
user defines a shuffler function (which perversely might not, or might fail to, 
shuffle anything), it does not shuffle anything.

Thanks for taking the time to answer my question. Neil

> On 16 Oct 2018, at 2:38 am, Chris Hopkins  wrote:
> 
> I've edited the example very slightly at:
> https://play.golang.org/p/s7CUSbS8P3I
> 
> Let's break this down.
> Think about how you might shuffle a pack of cards, a simple way is to swap 2 
> cards around at a time. As long as you exchange enough cards enough times and 
> both cards you chose are randomly picked, eventually you'll have shuffled the 
> pack. Please be happy with that as a concept before going further.
> 
> The rand.Shuffle therefore doesn't care about what it has to shuffle. All it 
> "thinks" about is: swap element 2 and 7, swap element 24 and 9 etc. (the 
> numbers aren't important here, just that anything in an array can be shuffled 
> by giving these sorts of instructions). All it needs to know is how long the 
> array it has to shuffle is, and "who" can swap things around. I'll repeat 
> that as it might not be obvious. It doesn't have to know how to swap things, 
> it doesn;t have to know anything about the things. If I told you to shuffle 
> 52 cards by shouting out numbers, the exact same instruction if you were 
> instead shuffling 52 cars, or airplanes, or dogs; it's the number of things 
> in the list and the numbers given as instructions that matter. It therefore 
> only has to know of a function that can do this swap around. So we also pass 
> it what I have called swapper. Who is an agent who you say, swap 2 and 7, 24 
> and 9, etc and it will do that.
> So it can call swapper with i and j set to two values and swapper does the 
> swap.
> 
> So how does this play into go:
> Well we've declared the initial array as an array of words.
> We've now declared swapper as someone who can carry out the function of 
> swapping any 2 items in that array, that is the item at location i gets put 
> at the position j was and the item at location j gets put where i was. I 
> explicitly declared swapper as a func that takes two integers as that's the 
> only thing rand.Shuffle knows or cars about the function. It just calls it a 
> whole bunch of times, doesn't pay attention to anything it does, it just 
> trusts it to do what needs to be done.
> So as far as rand.Shuffle goes, it needs how many items are in the array, and 
> a function that it can call with two integer parameters. so we sat to 
> rand.shuffle what the length of the array is, and to use swapper.
> 
> And that's it. Don't worry about how rand.Shuffle works (until you want to). 
> Yes it's a good bit of computer science to understand how it works, but it's 
> also good computer science to accept that you don't need to know how things 
> work under the hood either.
> 
> If that overly wordy version helps?
> 
> Chris
>> On Monday, 15 October 2018 15:06:58 UTC+1, Neil Higgins wrote:
>> 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 swaps the elements 
>> with indexes i and j.
>> 
>> 
>> And here's the example:
>> 
>> package main
>> 
>> import (
>> "fmt"
>> "math/rand"
>> "strings"
>> )
>> 
>> func main() {
>> words := strings.Fields("ink runs from the corners of my mouth")
>> rand.Shuffle(len(words), func(i, j int) {
>> words[i], words[j] = words[j], words[i]
>> })
>> fmt.Println(words)
>> 
>> }
>> 
>> Why can't I understand a word of it?
>> (This is not atypical, by the way - and not just for go - so if someone can 
>> educate me, I might suddenly start prospering in the software game)
>> 
>> Issues (for me):
>> Shuffle doesn't seem to swap anything (the thing you want shuffled isn't 
>> even an argument)
>> As I read it the example, it should only swap two words (index i and j) but 
>> it seems to shuffle the everything
>> What's this bloody "func" thing???
>> Why doesn't "swap" appear in the example?
>> Yours sincerely,
>> Confused
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/ICTwCqa8SgE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-10-15 Thread Chris Hopkins
I've edited the example very slightly at:
https://play.golang.org/p/s7CUSbS8P3I

Let's break this down.
Think about how you might shuffle a pack of cards, a simple way is to swap 
2 cards around at a time. As long as you exchange enough cards enough times 
and both cards you chose are randomly picked, eventually you'll have 
shuffled the pack. Please be happy with that as a concept before going 
further.

The rand.Shuffle therefore doesn't care about what it has to shuffle. All 
it "thinks" about is: swap element 2 and 7, swap element 24 and 9 etc. (the 
numbers aren't important here, just that anything in an array can be 
shuffled by giving these sorts of instructions). All it needs to know is 
how long the array it has to shuffle is, and "who" can swap things around. 
I'll repeat that as it might not be obvious. It doesn't have to know how to 
swap things, it doesn;t have to know anything about the things. If I told 
you to shuffle 52 cards by shouting out numbers, the exact same instruction 
if you were instead shuffling 52 cars, or airplanes, or dogs; it's the 
number of things in the list and the numbers given as instructions that 
matter. It therefore only has to know of a function that can do this swap 
around. So we also pass it what I have called swapper. Who is an agent who 
you say, swap 2 and 7, 24 and 9, etc and it will do that.
So it can call swapper with i and j set to two values and swapper does the 
swap.

So how does this play into go:
Well we've declared the initial array as an array of words.
We've now declared swapper as someone who can carry out the function of 
swapping any 2 items in that array, that is the item at location i gets put 
at the position j was and the item at location j gets put where i was. I 
explicitly declared swapper as a func that takes two integers as that's the 
only thing rand.Shuffle knows or cars about the function. It just calls it 
a whole bunch of times, doesn't pay attention to anything it does, it just 
trusts it to do what needs to be done.
So as far as rand.Shuffle goes, it needs how many items are in the array, 
and a function that it can call with two integer parameters. so we sat to 
rand.shuffle what the length of the array is, and to use swapper.

And that's it. Don't worry about how rand.Shuffle works (until you want 
to). Yes it's a good bit of computer science to understand how it works, 
but it's also good computer science to accept that you don't need to know 
how things work under the hood either.

If that overly wordy version helps?

Chris
On Monday, 15 October 2018 15:06:58 UTC+1, Neil Higgins wrote:
>
> *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 swaps the 
> elements with indexes i and j. 
>
> *And here's the example*:
>
> package main
>
> import (
> "fmt"
> "math/rand"
> "strings"
> )
>
> func main() {
> words := strings.Fields("ink runs from the corners of my mouth")
> rand.Shuffle(len(words), func(i, j int) {
> words[i], words[j] = words[j], words[i]
> })
> fmt.Println(words)
>
> }
>
> *Why can't I understand a word of it?*
> (This is not atypical, by the way - and not just for go - so if someone 
> can educate me, I might suddenly start prospering in the software game)
>
> Issues (for me):
>
>- Shuffle doesn't seem to swap anything (the thing you want shuffled 
>isn't even an argument)
>- As I read it the example, it should only swap two words (index i and 
>j) but it seems to shuffle the everything
>- What's this bloody "func" thing???
>- Why doesn't "swap" appear in the example?
>
> Yours sincerely,
> *Confused*
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.