简体   繁体   English

Circumflex标志/ Pin / Cap操作员(^)在Elixir中做了什么?

[英]What does the Circumflex sign/Pin/Cap operator (^) do in Elixir?

I was browsing through the Ecto documentation, when i got to the interpolation part, where Ecto uses the Circumflex(^) sign, like so. 我正在浏览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

Made me wonder, what does it do? 让我想知道,它做了什么? :-) :-)

In Elixir, the pin operator is used in pattern matching to match on the current value of a variable. 在Elixir中,引脚运算符用于模式匹配以匹配变量的当前值。 You can read more about it here: http://elixir-lang.org/getting-started/pattern-matching.html 您可以在这里阅读更多相关信息: http//elixir-lang.org/getting-started/pattern-matching.html

Ecto changes the pin operator to mean query interpolation where you pass an Elixir value to the query. Ecto将pin运算符更改为表示将Elixir值传递给查询的查询插值。 You could argue their behaviour are somewhat similar, because the database is effectively running the query trying to find a value that matches, but the easiest way is to think of it is indeed as query interpolation. 你可以说他们的行为有点类似,因为数据库有效地运行查询试图找到匹配的值,但最简单的方法是将其视为查询插值。 More info here: http://hexdocs.pm/ecto/Ecto.Query.html 更多信息: http//hexdocs.pm/ecto/Ecto.Query.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM