gpt4 book ai didi

operators - 这些运算符在 Elixir 中是什么意思? ~>>,<<~

转载 作者:行者123 更新时间:2023-12-04 10:24:17 27 4
gpt4 key购买 nike

这些运算符在 Elixir 中是什么意思? ~>>, <<~
它们列在这里 http://elixir-lang.org/getting-started/basic-operators.html

我收到以下错误:

iex(28)> b=1
1
iex(29)> b~>>1
** (CompileError) iex:29: undefined function ~>>/2

最佳答案

有一些运算符目前没有意义,但您可以在您定义的宏中使用它们,或者只是将它们定义为函数。例如:

defmodule Operators do
def a ~>> b do
a + b
end
end

defmodule Test do
def test do
import Operators

1 ~>> 2
end
end

IO.inspect(Test.test) # => 3

总体思路是 Elixir 想要避免运算符激增(想想定义数十个新运算符的库),因此在定义宏时,您需要使用已经存在的宏。

关于operators - 这些运算符在 Elixir 中是什么意思? ~>>,<<~,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33668981/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com