<p>I'm trying to understand <a href="https://github.com/google/hilbert/blob/master/hilbert.go#L61" rel="nofollow">this</a> bit of code, specifically, here we use variables <code>x</code>, and <code>y</code> but I can't see anywhere where they've been declared, much less initialized. I thought maybe they become initialized as 0 but that doesn't seem to work in this example <a href="https://play.golang.org/p/RVB1yZeiYEk" rel="nofollow">here</a> thanks!</p>
<hr/>**评论:**<br/><br/>DeedleFake: <pre><p>They're declared in the return values in the function signature. They, like all declared but unassigned variables in Go, start with zero values in them, which is 0 in this case.</p>
<p>Edit: To clarify, like arguments, functions can have named return values. It works like this:</p>
<pre><code>func Example() (n int) {
return n // Returns 0.
}
</code></pre></pre>joshlemer: <pre><p>Ah, got it thanks!</p></pre>danmickla: <pre><p>Well, no, they're the function arguments. 't' and 'err' are the return values.</p></pre>DeedleFake: <pre><pre><code>func (s *Hilbert) Map(t int) (x, y int, err error)
</code></pre>
<p>What? No they're not. <code>t</code> is an argument. <code>x</code>, <code>y</code>, and <code>err</code> are returns.</p></pre>mborawi: <pre><p>Its works fine if you declare the variables to recieve those values <a href="https://play.golang.org/p/timTW21MlK7" rel="nofollow">https://play.golang.org/p/timTW21MlK7</a></p></pre>SeriousM00nlight: <pre><p>X and Y came from mommy and daddy.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传