Erlang:哪种模式匹配更有效(列表)?
我正在阅读“实用编程 Erlang”,其中有一个定义如下的函数:
split("\r\n\r\n" ++ T, L) -> {reverse(L), T};
split([H|T], L) -> split(T, [H|L]);
split([], _) -> more.
我感兴趣的是第一个匹配项,即 "\r\n\r\n" ++ T
- is there我想出的这种模式与类似模式之间的性能差异:[13,10,13,10|T]
?或者说它们是等价的?
我知道这是一个非常简单的问题,我(可能)可以自己检查一下,但是如果存在差异,我想知道为什么会出现这种情况。
谢谢!
I'm going through "Pragmatic Programming Erlang" where there is a function defined like this:
split("\r\n\r\n" ++ T, L) -> {reverse(L), T};
split([H|T], L) -> split(T, [H|L]);
split([], _) -> more.
What interests me is first match, namely "\r\n\r\n" ++ T
- is there performance difference between such a pattern and similar one, that I came up with: [13,10,13,10|T]
? Or are they equivalent?
I know it's very simple question and that I could (probably) check it myself, but if there is a difference, I'd like to know why that is the case.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
"\r\n\r\n" ++ T
只是[13,10,13,10|T]
的语法糖。它应该表现相同。如果没有,那就有问题了;-)"\r\n\r\n" ++ T
is just syntax sugar for[13,10,13,10|T]
. It should perform same. If not there is something wrong ;-)