<p>If they can appear as unquoted at the package declaration, why do they need to be quoted when imported?</p>
<p>EDIT: Thanks for the answers, everyone!</p>
<hr/>**评论:**<br/><br/>catfix: <pre><p>Probably because you're referring to a path when importing, not a package name.</p></pre>jrv: <pre><p>Exactly. The last component of the path name does not actually need to equal the imported package name (though it usually is the same).</p></pre>avrtno: <pre><p>It's a string because the interpretation of the value is defined by the implementation and not the language. </p></pre>davecheney: <pre><p>That's probably the best answer, but there are some practicalities to consider</p>
<pre><code> import "github.com/person/repo/why would you do/this"
import banana "github.com/fruit/apple"
</code></pre>
<p>Both of these examples would be hard/difficult/inconsistent/impossible without the quoting.</p></pre>dericofilho: <pre><p>In shorter terms, it avoids ambiguity in the grammar. </p></pre>warmans: <pre><p>In one of the go convention keynotes (2014?) Rob Pike talks specifically about this question. IIRC it was implemented as a string because they were not sure what information it would ultimately contain and wanted to make it simple to change in future.</p>
<p>Probably this one: <a href="https://www.youtube.com/watch?v=VoS7DsT1rdM" rel="nofollow">https://www.youtube.com/watch?v=VoS7DsT1rdM</a></p></pre>will_alexander: <pre><p>You're right! He talks about it at <a href="https://www.youtube.com/watch?v=VoS7DsT1rdM&t=15m23s" rel="nofollow">15:23</a>. Thanks for the info.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传