ERlANG - 将列表拆分为子列表
所以我的另一篇文章中的一个好人很快就解决了一个问题。
现在我是 Erlang 的初学者,需要对另一个函数的语法有一点帮助,该函数对我上一篇文章的结果起作用。
例如,我现在有:
Reply = [<<56,45,34,07,45,67,34>>, <<12,23,56,07,67,67>>, <<55,23,45,07,89,56>>]
我需要将其进一步拆分为:
[ [<<56,45,34>>,<<45,67,34>>], [<<12,23,56>>,<<67,67>>] , [<<55,23,45>>, <<89,56>>] ]
本例中的分隔符是 <<07>>>
此代码过程是二进制文件
parse(Reply) -> binary:split(Reply, <<07>>, [global]).
,但现在我如何递归地遍历数组并再次执行此操作。
这是我当前代码的一个示例:
parse(Reply) -> binary:split(Reply, <<01>>, [global]).
parse2(Reply) -> binary:split(Reply, <<07>>, [global]).
func1(Done) -> [parse2(X) || X <- Done].
%%blah blah - get to the executing functions code
Done = parse(Reply),
Done1 = func1(Done),
我知道它必须是非常简单的东西,最后一个代码确实让我满意。
最好的, -B
So this I just had one problem solved very quickly by a nice guy on my other post.
ERLANG - Splitting Lists into sub list
Now I am a beginner at Erlang and need a little help with the syntax of another function that does work on the result from my previous post.
For example, I now have:
Reply = [<<56,45,34,07,45,67,34>>, <<12,23,56,07,67,67>>, <<55,23,45,07,89,56>>]
And I need to split it further to:
[ [<<56,45,34>>,<<45,67,34>>], [<<12,23,56>>,<<67,67>>] , [<<55,23,45>>, <<89,56>>] ]
The delimiter in this example is <<07>>
This code process's the binary
parse(Reply) -> binary:split(Reply, <<07>>, [global]).
But now how can I recursively go through the array and do it again.
Here is an example of my current code:
parse(Reply) -> binary:split(Reply, <<01>>, [global]).
parse2(Reply) -> binary:split(Reply, <<07>>, [global]).
func1(Done) -> [parse2(X) || X <- Done].
%%blah blah - get to the executing functions code
Done = parse(Reply),
Done1 = func1(Done),
I know it has to be something super simple the last one sure had me.
Best,
-B
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用列表推导式将函数应用于列表的每个元素。该功能与您的上一个问题几乎相同:
另一个选择是使用lists:map/2:
Use a list comprehensions to apply a function to every element of a list. The function is pretty much the same as for your last question:
Another option is to use lists:map/2:
想通了,请随时告诉我是否有更有效的方法 - 或者 - 只是你的方法,毕竟我正在学习。
-B
Figured it out please feel free to let me know if there is a more efficient way - or - just your way, I am learning after all.
-B