“?”是什么意思?运算符在 Elixir 中做什么?
Ecto 源代码使用表达式 ?0
, ?1
等。您可以看到他们如何评估:
iex(14)> ?0
48
iex(15)> ?1
49
iex(16)> ?2
50
但这是什么意思?这是非常难寻找的。 ?
实际上有什么作用?
The Ecto source code makes use of expressions ?0
, ?1
, etc. You can see how they evaluate:
iex(14)> ?0
48
iex(15)> ?1
49
iex(16)> ?2
50
What does that mean though? This is very hard to search for. What does the ?<character>
actually do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自: https: //elixir-lang.org/getting-started/binaries-strings-and-char-lists.html#unicode-and-code-points
如果您不熟悉代码点:
?
还可以以有趣的方式用于 模式匹配 和Elixir 文档< /a> 还澄清这只是语法。正如@sabiwara 指出的:
正如 @Everett 在评论中指出的,有一个有用的包名为
Xray
提供了一些方便的实用函数来帮助理解发生了什么事。例如
Xray.codepoint(some_char)
可以执行?
的操作,但它适用于变量,而?
仅适用于文字。Xray.codepoints(some_string)
将执行以下操作整个字符串。From: https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html#unicode-and-code-points
If you aren't familiar with code points:
The
?<character>
can also be used in interesting ways for pattern matching and guard clauses.The Elixir docs on it also clarify that it is only syntax. As @sabiwara points out:
As @Everett noted in the comments, there is a helpful package called
Xray
that provides some handy utility functions to help understand what's happening.For example
Xray.codepoint(some_char)
can do what?<char>
does but it works for variables whereas?
only works with literals.Xray.codepoints(some_string)
will do the whole string.