英文:
Golang Package Import
问题
我正在尝试编译以下代码:
package main
import (
"fmt"
"code.google.com/p/go.text/unicode/norm"
)
func main() {
fmt.Println(norm.IsNormalString("ŋ̊"))
}
我已经安装了unicode/norm包。我使用以下命令进行编译:
go build -o ipa ipa.go
不幸的是,我得到了以下错误:
# command-line-arguments
./ipa.go:9: undefined: norm.IsNormalString
make: *** [ipa] Error 2
看起来包已经被正确导入,但我无法访问任何其成员。我尝试将调用的方法更改为norm的另一个方法,但仍然出现错误。这让我相信我对Go的包系统有一些基本的误解。
英文:
I am attempting to get the following code to compile:
package main
import (
"fmt"
"code.google.com/p/go.text/unicode/norm"
)
func main() {
fmt.Println(norm.IsNormalString("ŋ̊"))
}
I have installed the unicode/norm package. I compile with the command:
go build -o ipa ipa.go
Unfortunately, I get the following error:
# command-line-arguments
./ipa.go:9: undefined: norm.IsNormalString
make: *** [ipa] Error 2
It seems that the package is being imported correctly, but I cannot access any of its members. I have tried changing the method from being called to another from norm, but I still get the error. This leads me to believe that I'm fundamentally misunderstanding something about go's package system.
答案1
得分: 1
IsNormalString
不是一个函数,而是Form
类型的方法。例如,
package main
import (
"code.google.com/p/go.text/unicode/norm"
"fmt"
)
func main() {
fmt.Println(norm.NFC.IsNormalString("ŋ̊"))
}
输出结果为:
true
英文:
> func (Form) IsNormalString
>
> func (f Form) IsNormalString(s string) bool
>
> IsNormalString returns true if s == f(s).
IsNormalString
is not a function, it's a method on type Form
. For example,
package main
import (
"code.google.com/p/go.text/unicode/norm"
"fmt"
)
func main() {
fmt.Println(norm.NFC.IsNormalString("ŋ̊"))
}
Output:
true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论