gpt4 book ai didi

dictionary - Erlang异常错误-没有函数子句匹配列表:map - what am I missing?

转载 作者:行者123 更新时间:2023-12-01 21:53:47 25 4
gpt4 key购买 nike

我正在研究 Euler 8。经过一番阅读后,我决定使用 map 函数可以解决我的问题。将一个简单的测试程序放在一起以确保我理解这些概念是不够的。

从外壳内部。

1> List = {3, 1, 4}.
{3,1,4}

2> io:format("oh my ~w ~n", [List]).
oh my {3,1,4}
ok

3> lists:map(fun (Z) -> Z * Z end , List).
** exception error: no function clause matching
lists:map(#Fun<erl_eval.6.80247286>,{3,1,4})

我看到了乐趣,以及消息中的列表。我在这里缺少什么概念?

最佳答案

你的列表实际上是一个元组。 {} 用于元组,[] 用于列表。

你的例子应该是:

1> List = [3,1,4].
[3,1,4]
2> lists:map(fun(Z) -> Z*Z end, List).
[9,1,16]

关于dictionary - Erlang异常错误-没有函数子句匹配列表:map - what am I missing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com