Erlang:哪种模式匹配更有效(列表)?

发布于 2024-12-18 05:20:56 字数 384 浏览 7 评论 0原文

我正在阅读“实用编程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2024-12-25 05:20:56

"\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 ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文