Circumflex sign/Pin/Cap 运算符 (^) 在 Elixir 中有什么作用?
What does the Circumflex sign/Pin/Cap operator (^) do in Elixir?
我正在浏览 Ecto 文档,当我到达插值部分时,Ecto 在其中使用了 Circumflex(^) 符号,就像这样。
def with_minimum(age, height_ft) do
from u in User,
where: u.age > ^age and u.height > ^(height_ft * 3.28)
end
让我想知道,它有什么作用? :-)
在 Elixir 中,pin 运算符用于模式匹配以匹配变量的当前值。您可以在这里阅读更多相关信息:http://elixir-lang.org/getting-started/pattern-matching.html
Ecto 将 pin 运算符更改为表示将 Elixir 值传递给查询的查询插值。您可能会争辩说它们的行为有些相似,因为数据库实际上是 运行 试图找到匹配值的查询,但最简单的方法是将其视为查询插值。更多信息在这里:http://hexdocs.pm/ecto/Ecto.Query.html
我正在浏览 Ecto 文档,当我到达插值部分时,Ecto 在其中使用了 Circumflex(^) 符号,就像这样。
def with_minimum(age, height_ft) do
from u in User,
where: u.age > ^age and u.height > ^(height_ft * 3.28)
end
让我想知道,它有什么作用? :-)
在 Elixir 中,pin 运算符用于模式匹配以匹配变量的当前值。您可以在这里阅读更多相关信息:http://elixir-lang.org/getting-started/pattern-matching.html
Ecto 将 pin 运算符更改为表示将 Elixir 值传递给查询的查询插值。您可能会争辩说它们的行为有些相似,因为数据库实际上是 运行 试图找到匹配值的查询,但最简单的方法是将其视为查询插值。更多信息在这里:http://hexdocs.pm/ecto/Ecto.Query.html