RosettaCodeData/Task/Associative-array-Merging/M2000-Interpreter/associative-array-merging.m...

34 lines
721 B
Plaintext

module mergeList {
a=list:="name":="Rocket Skates", "price":=12.75, "color":="yellow"
b=list:="price":=15.25, "color":="red", "year":=1974
c=list
bb=each(a)
while bb {
append c, eval$(bb!):=eval(bb)
}
bb=each(b)
while bb {
if exist(c, eval$(bb!)) then
return c, eval$(bb!):=eval(bb)
else
append c, eval$(bb!):=eval(bb)
end if
}
bb=each(c)
Print format$(" |{0:8}|{1}", "Key", "Value")
Gosub simple
while bb {
fun1(bb^+1, eval$(bb!),eval(bb))
}
Gosub simple
sub fun1(n, a as string, b as variant)
local string c=if$(type$(b)="String"->quote$(b), ""+b)
Print format$("{0::-2}|{1:-8}|{2:15}|", n, quote$(a), c)
end sub
simple:
Print "--+--------+---------------+"
Return
}
mergeList