Created
October 21, 2017 19:08
-
-
Save ygrenzinger/28b6334ddd20742926a75e106e4eb921 to your computer and use it in GitHub Desktop.
Transform to Records in Oz Mooc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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