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

Adams Christian <>
Wed Aug 17 23:27:26 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Maybe dumb .. but why don't you just

RL = lists:reverse(List).
"654" ++ RTail = RL.
Head = lists:reverse(RTail).

Just my 2c ..

CA

Am 16.08.2011 um 13:23 schrieb James Churchman:

> 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
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

CHRISTIAN ADAMS
Software Systems Engineer
Fon: +49 651 99554792


SOL VENETUS Software GmbH
Sebastian-Kneipp-Str. 2 - 86482 Aystetten - Germany
Fon: +49 170 7762480
Fax: +49 821 4865786
Geschäftsführer: Benjamin Hilbig
Sitz der Gesellschaft: Aystetten
Amtsgericht Augsburg, HRB 24559
USt-IdNr.: DE267014985

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org

iEYEARECAAYFAk5MMj4ACgkQr81gVylJyzFG1ACeI47hG24NJC2/5xRm+ZQw2ura
AqwAoOL6Ch259AymGgGTVh5p2Q513dxS
=OQ1H
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list