Skip to content

Instantly share code, notes, and snippets.

@tsloughter
Created July 14, 2011 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsloughter/1081719 to your computer and use it in GitHub Desktop.
Save tsloughter/1081719 to your computer and use it in GitHub Desktop.
set(Vals, Rec) ->
F = fun ([], R, _F1) -> R;
([{field, V} | T], R, F1) ->
F1(T, R#hello{field = V}, F1)
end,
F(Vals, Rec, F).
vs
f_set_2(Rname, Flds, L) ->
{function, L, fname(set), 2,
[{clause, L, [{var, L, 'Vals'}, {var, L, 'Rec'}], [],
[{match, L, {var, L, 'F'},
{'fun', L,
{clauses,
[{clause, L, [{nil,L},
{var,L,'R'},
{var,L,'_F1'}],
[],
[{var, L, 'R'}]} |
[{clause, L,
[{cons, L, {tuple, L, [{atom, L, Attr},
{var, L, 'V'}]},
{var, L, 'T'}},
{var, L, 'R'},
{var, L, 'F1'}],
[],
[{call, L, {var, L, 'F1'},
[{var,L,'T'},
{record, L, {var,L,'R'}, Rname,
[{record_field, L,
{atom, L, Attr},
{var, L, 'V'}}]},
{var, L, 'F1'}]}]} || Attr <- Flds]]}}},
{call, L, {var, L, 'F'}, [{var, L, 'Vals'},
{var, L, 'Rec'},
{var, L, 'F'}]}]}]}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment