Parallel list assignment in Red language

Viewed 101

I have 2 lists:

alist: [a b c d]
blist: [1 2 3 4]

(In reality they are long lists). How can I assign variables in alist to corresponding values in blist in one go? Hence a becomes 1, b becomes 2 and so on.

I tried:

foreach i alist j blist [i: j]

But it give following error:

*** Script Error: j has no value
*** Where: foreach
*** Stack: 

I also tried:

i: 1
while [true] [ 
    if i > (length? alist) [break]
    alist/i: blist/i  
    i: i + 1
]

But it also does not work:

*** Script Error: cannot set none in path alist/i:
*** Where: set-path
*** Stack: 

alist/i and blist/i return none (on checking with print command).

Similar question are there for other languages also, e.g.: Parallel array assignment in PHP and Parallel assignment in Java? . Thanks for your help.

1 Answers
Related