[erlang-questions] Help please with list syntax

Donald Steven t6sn7gt@REDACTED
Fri Oct 14 19:48:49 CEST 2016


Hi all,

I'm sorry to ask such a simple question, but "I've tried everything" and 
I'm still getting nowhere.

----------------------------------------------------------------------------------

The intent is simply at create a list 'L' of (MIDI) velocities, of 
length 'Events'.  The calling function is:

VelocityL = makeVelocityL(Events, SoftestNote, LoudestNote, []),

which should return something like (if 'Events' were to equal 3): [40, 
42, 91]

I'm testing this by following the above line of code with:

io:format("VelocityL ~p~n", [VelocityL]),

but this produces nonsense like: "(*["  (including the double quotes at 
either end

----------------------------------------------------------------------------------

The function that is called is:

makeVelocityL(     0,           _,           _, L) -> lists:reverse(L);
makeVelocityL(Events, SoftestNote, LoudestNote, L) ->

     io:format("(for testing purposes) Events: ~p, SoftestNote: ~p, 
LoudestNote: ~p, L: ~p~n", [Events, SoftestNote, LoudestNote, L]),
     Velocity = trunc(rand:uniform() * (LoudestNote - SoftestNote)) + 
SoftestNote,
     io:format("(For testing purposes) Velocity: ~p~n", [Velocity]),
     makeVelocityL(Events - 1, SoftestNote, LoudestNote, [Velocity | L]).

and the output of the io:format statements is:

(for testing purposes) Events: 3, SoftestNote: 36, LoudestNote: 96, L: []
(For testing purposes) Velocity: 40
(for testing purposes) Events: 2, SoftestNote: 36, LoudestNote: 96, L: "("
(For testing purposes) Velocity: 42
(for testing purposes) Events: 1, SoftestNote: 36, LoudestNote: 96, L: "*("
(For testing purposes) Velocity: 91

so clearly the values are OK but 'L' is nonsense.  So, the problem must 
be in the recursion statement:

     makeVelocityL(Events - 1, SoftestNote, LoudestNote, [Velocity | L]).

but I've tried every combination and order of | and ++ to no avail.

----------------------------------------------------------------------------------

Your help would be greatly appreciated.

Thanks.

Don




More information about the erlang-questions mailing list