<div dir="ltr">For better understanding Erlang lists will be better address to Lisp lists. Actually there r no lists at all. There are only cells linked together. It'll be good to take parallel line with Lisp:<div>cons-cell consist left and right value:</div><div>(1 . 2) - 1 is left value, 2 - right one</div><div>> (cons 1 2) </div><div><---- (1 . 2)</div><div><br></div><div>left value named 'car' and right - 'cdr'.</div><div>'cdr' value can be a link to another cons-cell.</div><div><br></div><div>for construct list in Lisp u should bring all cells together via 'cdr' links.</div><div>the tail 'cdr' element linked with 'nil'.</div><div><br></div><div>it looks like this:</div><div>>(cons 1 (cons 2 (cons 3 nil))) </div><div><---- (1, 2, 3)</div><div><br></div><div>the same thing in Erlang:</div><div>there is a cons-cell:</div><div>> [1 | 2]. </div><div><---- [1 | 2].</div><div><br></div><div>u can compose Erlang list in Lisp style:</div><div>> [1 | [2 | [3 | []]]].</div><div><---- [1,2,3]. </div><div><br></div><div>Erlang list - is a sequence of linked cons-cells also. </div><div>tail cell should point to []. (like 'nil' in Lisp).</div><div>[1, 2 | 3] - incorrect Erlang list cuz it contains cell which 'cdr' element isn't link.</div><div>[1, 2 | [3 | []]] or [1, 2 | [3]] - correct Erlang list cuz each 'cdr' element in each cell shows to another cell.</div><div><br></div><div>' | ' operator doesn't applied to lists. it works with "cells" and values. </div><div><br></div><div>also u can compare list with linked-list in C but it's incorrect cuz Erlang list can consist elements with different types.</div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-24 21:37 GMT+06:00 Cole Fichter <span dir="ltr"><<a href="mailto:cole.fichter@gmail.com" target="_blank">cole.fichter@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I came across the example:<div><br>> [1,2|3].<br>[1,2|3]<br></div><div><br></div><div>I understand that the pipe character, |, can be used to append an item to the head of the list or to pop an item off the list in a pattern match.</div><div><br></div><div>But what exactly is happening in the example above? Why does the evaluated expression still contain the pipe?</div><div><br></div><div>My best guess is that the final expression results in a match specification that could be used in a pattern match. However, that seems strange too because if so, we'd be popping two items off the list, which should be illegal.</div><div><br></div><div>Can someone shed some light?</div><div><br></div><div>Thanks!</div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>