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] = words[j], words[i] }`.
the `words` slice is not an argument, it's passed as part of a closure of
the anonymous function.

> As I read it the example, it should only swap two words (index i and j)
but it seems to shuffle the everything

It swaps only two words. But Shuffle calls the swap function several times
with different indices.

> What's this bloody "func" thing???

It's a keyword that introduces a definition of a function type or a named
or anonymous function.

> Why doesn't "swap" appear in the example?

It does. 'swap' is the declared name of the function to pass to
rand.Shuffle. The actual argument might be, for example, `foo`, `bar` or a
function literal (anonymous function) as seen above.

Also, see the source of rand.Shuffle here:
https://golang.org/src/math/rand/rand.go?s=7456:7506#L225

-- 

-j

-- 
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.

Reply via email to