list - 在 Erlang 中,内置的 head 和 tail 函数在哪里?
问题描述
我知道可以使用模式匹配从列表中提取头部和尾部。但这有必要吗?模块中没有调用head
or ,并且 erl. (它确实包括更强大的and ,但这些似乎是实现and的不自然冗长的方法。)tail
lists
nth/2
nthtail/2
head
tail
我也没有在顶级命名空间中找到它们:
Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]
Eshell V12.0 (abort with ^G)
1> head([1,2]).
** exception error: undefined shell command head/1
2> tail([1,2]).
** exception error: undefined shell command tail/1
解决方案
模式匹配是访问列表中头部和尾部的推荐方法。经常使用函数来访问它们的代码可能不是很好的惯用 Erlang。然而,在极少数情况下,这些功能确实很有用。您可以在此链接的名称hd
和tl
.
推荐阅读
- websocket - 未通过 websockets 从 mosquitto 接收有效负载
- php - 是否有检查参数是否存在且大于零的速记方法?
- asp.net - 如何从母版页上的链接中获取文本?
- python - 在拉伸中查找最大空值并生成标志
- javascript - 如何使以下代码快速、高效且时间复杂度高
- javascript - 关于node js express框架中的路由定义
- modeling - 将给定数学模型实现到 CPLEX
- cypress - 尝试将 typescript 与 cypress 一起使用时出错:“import”和“export”可能只出现在“sourceType:module”中
- python - 如何使用正则表达式更改数据记录的顺序并将其放在一个数据框中?
- r - 如何过滤掉R中每一行中的行?