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

Mar*_*var 6 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
Run Code Online (Sandbox Code Playgroud)

让我想知道,它做了什么?:-)

Jos*_*lim 4

在 Elixir 中,pin 运算符用于模式匹配,以匹配变量的当前值。您可以在这里阅读更多相关信息:http://elixir-lang.org/getting-started/pattern-matching.html

Ecto 将 pin 运算符更改为查询插值,您可以将 Elixir 值传递给查询。您可能会说它们的行为有些相似,因为数据库正在有效地运行查询,试图找到匹配的值,但最简单的方法是将其视为确实是查询插值。更多信息在这里: http: //hexdocs.pm/ecto/Ecto.Query.html