[erlang-questions] Updating a nested record

Donald Steven t6sn7gt@REDACTED
Sun May 15 19:52:54 CEST 2016


Hi everyone,

When I update the  'note' record below it updates correctly but the 
value returned is only the sub-record 'pressure', not the whole 'note' 
record.  I'd be most grateful for the right syntax.  Thanks.

Don

-module(metatest).

-export([main/0]).

-record(pressure, {initial, final, offset, scope}).
-record(wheel, {initial, final, contour, curve, offset, scope}).
-record(breath, {initial, final, contour, curve, offset, scope}).
-record(pan, {mode, initial, final, contour, curve, offset, scope}).
-record(bend, {initial, final, contour, curve, offset, scope}).
-record(note, {start, delta, duration, pitch, velocity,
             p1 = #pressure{}, p2 = #wheel{}, p3 = #breath{}, p4 = 
#pan{}, p5 = #bend{}}).
-record(controller, {start, status, change, data}).
-record(pitchbend, {start, status, data}).
-record(aftertouch, {start, status, data}).

main() ->

     N  = makemetaN(10, 20, 30, 40), io:format("~nOriginal note: ~p~n", 
[N]),
     N1 = N#note{delta = 99}, io:format("~nNote after updated delta: 
~p~n", [N1]),
     N2 = setNpressure(N, 50, 60, 70, 80), io:format("~nNote after 
updated pressure: ~p~n~n", [N2]).

makemetaN(Delta, Duration, Pitch, Velocity) ->
     #note{start = undefined, delta = Delta, duration = Duration, pitch 
= Pitch, velocity = Velocity}.

setNpressure(N, Initial, Final, Offset, Scope) ->
     N1 = N#note.p1#pressure{initial = Initial, final = Final, offset = 
Offset, scope = Scope}.





More information about the erlang-questions mailing list