Task

Define two associative arrays, where one represents the following "base" data:





 Key 
 Value


 "name" 
 "Rocket Skates"


 "price" 
 12.75


 "color" 
 "yellow"

And the other represents "update" data:





 Key 
 Value


 "price" 
 15.25


 "color" 
 "red"


 "year" 
 1974

Merge these into a new associative array that contains every key found in either of the source ones. Each key should map to the value in the second (update) table if that exists, or else to the value in the first (base) table. If possible, do this in a way that does not mutate the original two associative arrays. Obviously this should be done in a way that would work for any data, not just the specific data given here, but in this example the result should be:





 Key 
 Value


 "name" 
 "Rocket Skates"


 "price" 
 15.25


 "color" 
 "red"


 "year" 
 1974



include ..\Utilitys.pmt
 
def scand   /# dict key -- dict n #/
    0 var flag
    var ikey
    len for
        var i
        i 1 2 tolist sget
        ikey == if i var flag exitfor endif
    endfor
    flag
enddef
 
 
def getd    /# dict key -- dict data #/
    scand
    dup if get 2 get nip else drop "Unfound" endif
enddef
 
 
def setd    /# dict ( key data ) -- dict #/
    1 get rot swap
    scand
    rot swap
    dup if set else put endif
enddef
 
/# ---------- MAIN ---------- #/
 
( ( "name" "Rocket Skates" )
  ( "price" 12.75 )
  ( "color" "yellow" ) )
 
dup
 
( ( "price" 15.25 )
  ( "color" "red" )
  ( "year" 1974 ) )
 
len for
    get rot swap setd swap
endfor
 
swap
 
pstack
 