为什么此代码以这种方式工作?有没有一种方法可以用这种方式使用bar
完成我想要的? (我知道有替代品做模式相匹配的字符串)串联匹配的字符串插值
# Elixir 1.3.4
defmodule MyMod do
@foo "abc"
def concatenation_operator_with_interpolation do
bar = "abc"
"#{@foo}::" <> matchworks = "abc::xyz"
IO.puts matchworks # xzy
"#{bar}::" <> matchbroke = "abc::xyz" # cannot invoke remote function String.Chars.to_string/1 inside match
IO.puts matchbroke # never runs
end
end
MyMod.concatenation_operator_with_interpolation
必须与字符串插值有关。我可以用'“#{bar}”=“abc”'重现这一点。 –
'bar =“abc”; size = byte_size(bar); <<^bar :: binary-size(size)>><> matchworks =“abc :: xyz”' – Dogbert
是的,我想知道是否有什么我可以做的插补工作。以上内容不太简洁......你知道吗? –