[erlang-questions] 回复: What's this mean:[1|1]?It's it a bug?

饕餮 249505968@REDACTED
Wed Jul 3 12:21:08 CEST 2013

oh thank you!
I will just try to keep it out of my door

------------------ 原始邮件 ------------------
发件人: "Konstantin Tcepliaev"<f355@REDACTED>;
发送时间: 2013年7月3日(星期三) 晚上6:16
收件人: "饕餮"<249505968@REDACTED>; "erlang-questions"<erlang-questions@REDACTED>; 

主题: Re: [erlang-questions] What's this mean:[1|1]?It's it a bug?

That's what is called "improper list". Lists in Erlang are basically two pointers, to head and to tail, and both of them actually can be of any type.
List of, say, two elements - [1, 2] - is actually just a syntactic sugar for [1 | [2 | []]], where [] is a special value meaning "empty list". Obviously, anything can be used in its place.
Improper lists can lead to strange errors and definitely should be avoided. They probably can be used in place of 2-tuples when you need some crazy micro-optimization, because I think they're a bit faster. But still, do not try that at home.
03.07.2013, 14:03, "饕餮" <249505968@REDACTED>:
One of my new teammate found that this expression can work like list:nth(1,[1|1]) is legal.And the is_list([1|1]) is true
so what's this expression mean or it's just like some bug?
erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130703/da041110/attachment.htm>

More information about the erlang-questions mailing list