Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the | operator in erlang.

Tags:

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?

like image 729
AJed Avatar asked Feb 15 '23 14:02

AJed


1 Answers

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)

like image 98
johlo Avatar answered Feb 17 '23 04:02

johlo