[erlang-questions] Help please with list syntax

Stanislaw Klekot erlang.org@REDACTED
Fri Oct 14 19:57:20 CEST 2016


On Fri, Oct 14, 2016 at 01:48:49PM -0400, Donald Steven wrote:
> 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

~p format tries to write strings as strings, and since string is just
a list of small integers, it matches what you have there. In fact, 40
stands for '(', 42 is '*', and 91 is '['. You can check yourself:

#v+
1> [40, 42, 91] == "(*[".
true
#v-

What you want probably is to use ~w format, since it prints lists of
integers as just lists of integers.

-- 
Stanislaw Klekot



More information about the erlang-questions mailing list