[erlang-questions] Learning erlang - is this an efficient way to build a list?

graemebe <>
Sat Oct 13 18:58:26 CEST 2007


Thanks for the responses everyone. I was trying to build the list in reverse
order after reading that mentioned in Joe Armstrong's book. I did try the
X|L syntax at one point but for some reason I got a weird bug and abandoned
it. Have got it working now. I also like the other idea from GB for doing it
with lists:seq, which takes less code - one of the things I like about
erlang is that you can write cool functions in only a few chars.

>Yes, the important thing is to build the list in reverse order. '++' is
fine
>as long as the accumulator argument is to the right.
>
>In this simple case, the compiler will itself rewrite
>
>[spawn(fun ring:recv/0)] ++ L
>
>to
>
>[spawn(fun ring:recv/0)|L]
>
>so the cost is exactly the same.

-- 
View this message in context: http://www.nabble.com/Learning-erlang---is-this-an-efficient-way-to-build-a-list--tf4540288.html#a13191513
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list