[erlang-questions] List to proplist?

Richard O'Keefe <>
Tue Nov 11 00:56:01 CET 2008


On 8 Nov 2008, at 5:20 am, David Mercer wrote:

> On Monday, October 20, 2008, Richard O'Keefe wrote
>
>> A version of unfold that I prefer is
>>
>> unfold(State, Splitter) ->
>>     unfold(State, Splitter, []).
>>
>> unfold(State, Splitter, Acc) ->
>>     case Splitter(State)
>>       of []            -> lists:reverse(Acc)
>>        ; [Item|State1] -> unfold(State1, Splitter, [Item|Acc])
>>     end.
>
> Why is a cons cell, [Item|State1], preferred over a tuple, {Item,  
> State1}?

Because it *MEANS* a cons.
The algorithm uses [] to say "this State represents []"
and [Item|State1] to say "this State represents [Item|Rest]".

And yes, there is also a performance consideration that
I wasn't blind to, but would not have allowed to override
the mnemonic advantage had it gone the other way.





More information about the erlang-questions mailing list