我在深入探究菲尼克斯如何将模板渲染为碘甲烷,并发现了一些对我而言看起来很奇怪的列表。似乎我缺少涉及“竖线”或“垂直管道”字符(|
)的列表的基本语法。Elixir:这是什么样的列表还有竖条呢?
下面是一些例子我做明白:
# prepends 1 to the list [2, 3]
l = [1 | [2, 3]] #=> [1, 2, 3]
# matches the head and tail into variables
inspect_tail = fn ([_head | tail]) -> IO.inspect(tail) end
那些我得到。但是这是什么?
l = ["hi" | "there"] #=> ["hi" | "there"]
这似乎是对头部和尾部的名单:
is_list(["hi" | "there"]) #=> true
hd(["hi" | "there"]) #=> "hi"
tl(["hi" | "there"]) #=> "there"
...但如果给这样的列表中length(list)
功能给出了ArgumentError
。
这是什么,它用于什么?
多一点谷歌搜索让我觉得这可能是一个“不当名单” - 是吗? –
仍试图了解用例。正如[本文](http://www.evanmiller.org/elixir-ram-and-the-template-of-doom.html)所示,':re.replace'(与'Regex.replace'不同)返回一个不正确的列表:':re.replace(“sing”,“i”,“o”)#> [“s”,“o”,| “NG”]'。我知道它重用了现有的字符串,但我不明白为什么结果不是'[“s”,“o”,“ng”]' –