[erlang-questions] Clueless am I

Stefan Schmiedl s@REDACTED
Mon Apr 25 22:11:56 CEST 2016


> -----Ursprüngliche Nachricht-----
> Von: Donald Steven [mailto:t6sn7gt@REDACTED]
> Gesendet: Montag, 25. April 2016 21:40
> An: Stefan Schmiedl <s@REDACTED>; Hugo Mills <hugo@REDACTED>; erlang-
> questions@REDACTED
> Betreff: Re: AW: [erlang-questions] Clueless am I
> 
> Stefan and Hugo,
> 
> Is there any data structure in Erlang that will accept modification?

don't know, never needed one :-)

> This is quite beyond me as to how to add elements to a data structure.
> I've hit the same dead end with lists.  If one has, for example, a
database,
> and one wants to add a customer, do you really need to have a new (second)
> database?

yes ... and no.

yes: you get a reference to the new database
no: much of the "old" data structure can be reused

Lists are actually a good example for this type of thinking. They are made
of
"cells", which hold the value and a reference to the rest of the list.

You keep track of a list by a firm grasp on its first cell.
Adding a value to a given list comes down to wrapping the value into a new
cell, which references the "old first cell" as its rest.

So you're getting a new list on each "change", but all of the "old" data
structure
is reused.

BTW: Suffering a few headaches while getting used to these concepts is not
unusual :-)

s. 





More information about the erlang-questions mailing list