[erlang-questions] ++ to select the head ( instead of just the tail )

James Churchman jameschurchman@REDACTED
Tue Aug 16 13:23:25 CEST 2011


The ++ operator is not just a righthand side operator, but can in fact be a lefthand side operator in as far as I can tell just 1 case : 

When you know the head you wish to remove and getting the tail :

Eg in the shell: 

FullList = "123456".
"123" ++ Tail = FullList.
Tail wil now be "456"

However using it to get the head is not supported :

FullList = "123456".
Head ++  "456" = FullList.

gives : * 1: illegal pattern

Understandably this second type involves traversing the entire list, where the first does not, but it would still be a nice addition to erlang.

Was this not added as the first one expands out to simply [$1,$2,$3 | Tail] etc... but the second needs to expand to something more complex like an actual function the way list comprehensions do?

James


More information about the erlang-questions mailing list