Skip to content

Instantly share code, notes, and snippets.

@ygrenzinger
Created October 21, 2017 19:08
Show Gist options
  • Save ygrenzinger/28b6334ddd20742926a75e106e4eb921 to your computer and use it in GitHub Desktop.
Save ygrenzinger/28b6334ddd20742926a75e106e4eb921 to your computer and use it in GitHub Desktop.
Transform to Records in Oz Mooc
declare
fun {Transform L}
local Label Fields Values R in
Label = {List.nth L 1}
Fields = {List.nth L 2}
Values = {List.nth L 3}
R = {Record.make Label Fields}
local AssignValuesToFields in
fun {AssignValuesToFields Fs Vs}
if Fs == nil then R
else
if {List.is Vs.1} then R.(Fs.1) = {Transform Vs.1}
else R.(Fs.1) = Vs.1
end
{AssignValuesToFields Fs.2 Vs.2}
end
end
{AssignValuesToFields Fields Values}
end
end
end
{Browse {Transform [test [a b c] [[nested [a] [1]] b c]]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment