红色语言的并行列表分配 [英] Parallel list assignment in Red language
本文介绍了红色语言的并行列表分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个列表:
alist: [a b c d]
blist: [1 2 3 4]
(实际上,它们很长).如何一次性将alist中的变量分配给blist中的相应值?因此,a变为1,b变为2,依此类推.
(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.
我尝试过:
foreach i alist j blist [i: j]
但是它给出了以下错误:
But it give following error:
*** Script Error: j has no value
*** Where: foreach
*** Stack:
我也尝试过:
i: 1
while [true] [
if i > (length? alist) [break]
alist/i: blist/i
i: i + 1
]
但是它也不起作用:
*** Script Error: cannot set none in path alist/i:
*** Where: set-path
*** Stack:
alist/i
和blist/i
返回none
(通过打印命令检查).
alist/i
and blist/i
return none
(on checking with print command).
其他语言也有类似的问题,例如: PHP中的并行数组分配和 Java中的并行分配?.感谢您的帮助.
Similar question are there for other languages also, e.g.: Parallel array assignment in PHP and Parallel assignment in Java? . Thanks for your help.
推荐答案
简便的方法,将一个列表设置为另一个列表
easy way, set one list to the other
>> set alist blist
== [1 2 3 4]
>> a
== 1
>> b
== 2
>> c
== 3
>> d
== 4
>> alist
== [a b c d]
>> reduce alist
== [1 2 3 4]
>> get alist/1
== 1
和繁琐的方式
>> forall alist [alist/1: blist/(index? alist) ]
>> i: 2
== 2
>> get alist/:i
== 2
这篇关于红色语言的并行列表分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文