REBOL [
    Title:   "Hash2"
    Author:  "Aldo Calpini"
    Date:    05-Jul-2001
    File:    %hash2.r
]

NUM: to-integer to-string system/script/args
NUM: either NUM < 1 [ 1 ] [ NUM ]

hash1: make [] 9999

for i 0 9999 1 [
    append hash1 rejoin [ "foo_" i ]
    append hash1 i
]

hash2: make [] 9999

for i 1 NUM 1 [

    hash1: head hash1
    forskip hash1 2 [
        k: first hash1
        hash2: head hash2
        k2: select/skip hash2 k 2 
        either k2 == none [
            append hash2 k
            append hash2 0
            v: 0
            hash2: head hash2
            hash2: find/skip hash2 k 2
        ] [
            hash2: find/skip hash2 k 2
            v: second hash2
        ]
        v1: first select/skip hash1 k 2        
        v2: (v + v1)
        comment [
            hash2: head hash2
            hash2: find/skip hash2 k 2         
            hash2: next hash2
        ]
        hash2: next hash2
        change hash2 v2
        comment [        
            if error? try [ change hash2 v2 ] [ 
                print [ "error in change hash2 (k=" k ")" ]
                probe hash2 
            ]
        ]
    ]
    hash2: head hash2
]

hash1: head hash1
hash2: head hash2

write %output.rebol [ 
    select/skip hash1 "foo_1" 2
    select/skip hash1 "foo_9999" 2
    select/skip hash2 "foo_1" 2
    select/skip hash2 "foo_9999" 2
]