[erlang-questions] How to keep adding items to a data structure

Oliver Korpilla Oliver.Korpilla@REDACTED
Sun Apr 24 23:05:39 CEST 2016


Hello, Donald.

Lists are not fixed to one type like arrays in C are.
 
[[1,2,3],"hello",5,world] is a valid Erlang expression, even though the list contains another list, a string, a number, and an atom.

You might want to read a book like "Programming Erlang" to get into the language. I highly recommend it, it really helped laying down the basics and understand the design principles of the OTP shipped with Erlang.

Cheers,
Oliver
 

Gesendet: Sonntag, 24. April 2016 um 22:05 Uhr
Von: "Donald Steven" <t6sn7gt@REDACTED>
An: "Antonios Kouzoupis" <kouzan@REDACTED>, erlang-questions@REDACTED
Betreff: Re: [erlang-questions] How to keep adding items to a data structure
Hi Antonios,

You are kind and generous to help. I'll study this carefully. I will
be wanting to add a list or a record, not just numbers. Is this possible?

Don

On 04/24/2016 03:13 PM, Antonios Kouzoupis wrote:
> Hi Don,
>
> The way you iterate in Erlang and I guess in most functional programming
> languages is by recursive call. So if you want to add/append some
> numbers to a list, one way to go is the following:
>
> populate(Num) ->
> populate(Num, []).
>
> populate(0, Acc) ->
> Acc;
> populate(Num, Acc) ->
> populate(Num - 1, [Num | Acc]).
>
>
> Now if you call populate(100), you'll get the list [1,...,100]
>
> BR,
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions[http://erlang.org/mailman/listinfo/erlang-questions]



More information about the erlang-questions mailing list