<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>On Tue, Jan 22, 2019, at 3:10 PM, Donald Steven wrote:<br></div><blockquote type="cite" id="fastmail-quoted"><div>I would like to pass a list of some fields of a record to a function to <br></div><div>update those fields, leaving the other fields as they were. The list <br></div><div>will be different for each function call. For example, one call might <br></div><div>want to change fields 1, 2 and 7, another call only field 8, another <br></div><div>call fields 3 and 4. Of course, each field will have a unique name. <br></div><div>Each call to updateStatus (let's call it) would look like <br></div><div>updateStatus(Status, List_of_Fields_to_Update) -> code.<br></div><div><br></div><div>--------------------------------<br></div><div><br></div><div>I can't figure put how to do this economically, without a long <br></div><div>succession of tests like:<br></div><div><br></div><div>extract fieldnames from list...<br></div><div><br></div><div>case field1name of<br></div><div> true -> update field1;<br></div><div> false -> ok % do nothing<br></div><div>end,<br></div><div><br></div><div>repeat for each field...<br></div><div><br></div><div><br></div><div>--------------------------------<br></div><div><br></div><div>Any suggestions?<br></div></blockquote><div><br></div><div><br></div><div><div>Do you need it to be a record? This sounds like a use-case for maps:<br></div><div><div><br></div></div><div>update_fields(Data, []) -><br></div><div> Data;<br></div><div>update_fields(Data, [Field|Rest]) -><br></div><div> Value = maps:get(Field, Data),<br></div><div> NewValue = update_value(Value),<br></div><div> NewData = maps:put(Field, NewValue, Data),<br></div><div> update_fields(NewData, Rest).<br></div></div><div><br></div></body></html>