What are the unicode characters tat can be used as identifier ?

polaris · · 323 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Go allows to use unicode characters for function names. This is great because I can for instance create a function named héhé or with cyrilic or (I suppose) chinese characters. But we can&#39;t use a name composed of emoticons. </p> <p>What are the unicodes characters that can be used ? </p> <p>The Go language specification doesn&#39;t say much about the accepted characters (<a href="https://golang.org/ref/spec#Identifiers" rel="nofollow">https://golang.org/ref/spec#Identifiers</a>)</p> <hr/>**评论:**<br/><br/>nhooyr: <pre><p>The spec says unicode letters.</p> <p><a href="https://golang.org/pkg/unicode/#IsLetter" rel="nofollow">https://golang.org/pkg/unicode/#IsLetter</a> says that is category L.</p> <p>So on this list <a href="https://www.compart.com/en/unicode/category" rel="nofollow">https://www.compart.com/en/unicode/category</a> any of the categories starting with L are allowed.</p></pre>dabshores: <pre><p>This is the correct answer for anyone wondering.</p></pre>ChristophBerger: <pre><p>One further restriction: The first letter of an identifier must exist in uppercase and lowercase variants, to be able to determine visibility.</p></pre>TheMerovius: <pre><p><a href="https://play.golang.org/p/pHvnpZUtpc" rel="nofollow">No, it doesn&#39;t</a>. The spec says, that an <a href="https://golang.org/ref/spec#Exported_identifiers" rel="nofollow">identifier is exported</a>, if it&#39;s first letter is uppercase. If the first letter doesn&#39;t have an upper case variant it is, by definition, not upper case and thus not exported.</p></pre>ChristophBerger: <pre><p>Good catch, thanks, This shall teach me to revisit the specs before hitting reply. :) (edit: wording)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

323 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传