On Tue, Jan 22, 2019 at 7:59 PM <mountain...@gmail.com> wrote:
>
>      When i use the func, map slice as the key of map, it isn't work!
>      So  I lookup source  why, i find

You don't have to look at the source, you can look at the language
spec.  https://golang.org/ref/spec#Map_types "The comparison operators
== and != must be fully defined for operands of the key type; thus the
key type must not be a function, map, or slice."

In Go, function values are not comparable, so they can not be used as
map keys.  This is to avoid various sorts of confusion.  For example,
given this:

func F() func() int {
    i := 0
   return func() int {
        i++
        return i
    }
}

should F() == F()?  There is no obvious answer that clearly correct in
all cases, so we don't permit comparing function values at all.

Ian

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