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

Richard A. O'Keefe ok@REDACTED
Tue Apr 26 05:13:43 CEST 2016

On 25/04/16 3:48 AM, Donald Steven wrote:
> I'm very new to erlang (though quite comfortable with C), trying to 
> write a program to do some AI composition.   Can anyone please suggest 
> a solution to a very  basic problem I've been struggling with for 
> days, looking at lists, arrays, and records to no avail:
> ===
> How do I code the following in erlang (problem example is written in a 
> pseudo-C style):
> start with an empty music-event list-or-array-or-record
> for i = 1 to 1000
>     append new musical-event to the end of the music-event 
> list-or-array-or-record

Records are not sequences, so appending to them does not make sense.
Lists and tuples are sequences.

Is what you described *really* what you want,
or is what you want
    My_Event_Sequence = [new_musical_event(I) || I <- lists:seq(1, 1000)]
SML version:      List.tabulate 1000 new_musical_event
Haskell version:   [new_musical_event i | i <- [1..1000]]

More information about the erlang-questions mailing list