Meaning of [a]++b
Sebastian Strollo
seb@REDACTED
Thu Jan 16 20:13:16 CET 2003
"Eric Newhuis" <enewhuis@REDACTED> writes:
> Can someone provide or point me in the direction of an explanation of
> what this means?
>
> > [a] ++ b
It means lists:append([a], b).... :-)
> [a|b]
Which is an "inproper" list, i.e. a list where the last tail isn't an
empty list, []. E.g. [a] is a proper list, because hd([a]) -> 'a' and
tl([a]) -> [] and so is [a,b] because tl(tl([a,b])) -> []. But [a|b]
isn't a proper list because tl([a|b]) -> b. Not sure if this is the
best way to explain it though... :-) I guess it might be worth to
mention that after the | is the remainder of the list, but it isn't
printed when you have a proper list (the remainder is nil), here are
some examples from the shell:
> [a,b,c|[]].
[a,b,c]
> [a,b,c|[d,e]].
[a,b,c,d,e]
> [a,b,c|d].
[a,b,c|d]
The fact that append behaves this way is described in the man-page for
lists:append/1.
> It reminds me of
> something I saw in Lisp, the dot operator or something.
Yes it is equivalent of the "dotted pair" in lisp.
Cheers,
/Sebastian
More information about the erlang-questions
mailing list