Cannot reference the outstanding name m.β

Take a look at these two simple packages:

package m const β = 1 

 package main import ("m";"fmt") func main() { fmt.Println(m.β) } 

I get this error when I try to compile it:

 $ GOPATH=`pwd` go run a.go # command-line-arguments ./a.go:4: cannot refer to unexported name m.β ./a.go:4: undefined: m.β 

Why? I tried replacing β with B in both packages and it works, but I'm trying to use the correct character here. Perhaps for some reason both packages use homoglyphs or different encodings?

+7
go unicode packages
source share
4 answers

The go specs say the identifier is exported if

the first character of the identifier name is Unicode uppercase letter (Unicode class "Lu")

https://golang.org/ref/spec#Exported_identifiers

 func main() { fmt.Println(unicode.IsUpper('β')) } 

returns

 false 

http://play.golang.org/p/6KxF5-Cq8P

+11
source share

β is lowercase, so it is not exported and cannot be used outside of this package.

 fmt.Println(unicode.IsLower('β')) 

playground

+3
source share

The function, method in the exported package must begin with an uppercase letter. Yesterday I got into the same problem. Error importing custom packages in Go Lang

+1
source share

The first character of the name of the exported identifier must be a Unicode uppercase letter. For example,

 package main import ( "fmt" "unicode" ) const Β = 1 func main() { const ( GreekLowerβ = 'β' GreekUpperΒ = 'Β' ) fmt.Println(GreekLowerβ, unicode.IsUpper(GreekLowerβ)) fmt.Println(GreekUpperΒ, unicode.IsUpper(GreekUpperΒ)) } 

Output:

 946 false 914 true 

Go programming language specification

Exported Identifiers

An identifier can be exported to allow access to it from another package. The identifier is exported if both:

  • the first character of the identifier name is the Unicode uppercase letter (Unicode class "Lu"); and
  • an identifier is declared in a package block or is it a field name or a method name.

All other identifiers are not exported.


Greek alphabet : Β β beta p>

+1
source share

All Articles