[erlang-questions] What's the difference between tuple and list ?

attila.rajmund.nohl <>
Tue Sep 25 13:08:16 CEST 2007


On Tue, 25 Sep 2007, raocheng wrote:

> The Pragmatic Programming Erlang says:
> 1) Suppose you want to group a fixed number of items into a single
> entity.For this you'd use a tuple.
> 2) We use lists to store variable numbers of things.
>
> However, we know that variables in Erlang are in essence invariable. So what
> is the difference between tuple and list ?

Use list when you don't know how many elements will be used. In a code
like this:

loop([H | T] = L) ->
     loop(T).

in each subsequent call you'll have one less element in the parameter
list.

 				Bye,NAR
-- 
"Beware of bugs in the above code; I have only proved it correct, not
  tried it."



More information about the erlang-questions mailing list