关于|操作员在erlang。 [英] About the | operator in erlang.

查看:73
本文介绍了关于|操作员在erlang。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  NL = [[2,3],我们可以在erlang中创建一个嵌套列表, [1]]。 
[[2,3],[1]]

但是假设我们写了而是:

  OL = [[2,3] | 1]。 
[[2,3] | 1]

OL还是列表吗?有人可以详细说明什么是OL?

解决方案

这被称为不正确的列表,通常不会被使用。我认为大多数库函数都期望正确的列表(例如length([1 | 2])抛出不好的参数异常)。



对于某些用例,请参阅 Erlang中的不当列表的实际使用(可能是所有功能语言)


We can make a nested list in erlang by writing something like this:

 NL = [[2,3], [1]]. 
 [[2,3],[1]]

But assume we wrote it like this instead:

 OL = [[2,3]|1].
 [[2,3]|1]

Is OL still a list? Can someone please elaborate more what OL is?

解决方案

This is called an improper list and should typically not be used. I think most library functions expects proper lists (e.g. length([1|2]) throws bad argument exception). Pattern matching with improper lists works though.

For some use cases, see Practical use of improper lists in Erlang (perhaps all functional languages)

这篇关于关于|操作员在erlang。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆