5

我正在学习 Go,想知道是否有:=运算符的名称。如x := 4.

我能想到的最好的就是“蜘蛛脸”

例子

在此处输入图像描述
(来源:buzzfed.com

更新

我问的原因是因为我想知道您将如何像在结对编程会话中那样大声朗读代码。有人提出,运算符的正式名称是“短变量声明运算符”,但具有讽刺意味的是,这个名称太长了,不能经常使用。

你会怎么读这个x := 4?到目前为止,我有“前冒号等于四”还是“前蜘蛛面四”?有没有更好的想法?

4

5 回答 5

6

Go 编程语言规范将这些声明称为:=“短变量声明”。因此,该运算符将被称为“短变量声明运算符”。</p>

于 2013-12-30T00:07:35.710 回答
4

分配?或“已分配”。实际上,我会使用“分配”,但我必须输入至少 30 个字符...

于 2013-12-30T00:35:41.797 回答
3

“声明为”怎么说

x := 4

您会说:“将 ex 声明为四个”或“ex 声明为四个”

如果写成

var x = 4

也是正确的

于 2013-12-30T18:36:59.030 回答
1

This is just off the top of my head, but I'd call it "instantiate". IMHO, assign is not a good choice as it confuses it with the Pascal assignment operator. Assign is also the verb used for the "=" in go and most other computer languages.

"decinit" might work as a short-hand and that has no other meaning that I know of.

于 2013-12-30T17:49:38.743 回答
0

根据https://golang.org/ref/spec#Operators的规范,Operators combine operands into expressions.这绝对不是operator. (如果您不确定操作数或表达式到底是什么,请弄清楚它不能组合。否则,请始终检查规范https://golang.org/ref/spec#Expressions)。

规范https://golang.org/ref/spec#Short_variable_declarations中关于语言这方面的段落没有命名。

Effective Go 中可用的相同段落也没有命名,https://golang.org/doc/effective_go#redeclaration

搜索源,我可以找到它是如何定义的。

https://cs.opensource.google/go/go/+/master:src/go/token/token.go;drc=master;l=80

我得出的结论是它是定义令牌。

于 2021-09-15T10:40:28.230 回答