4

如何将字符串块转换为块?

要改变这一点:

keep rejoin['circle " " coord " " 5 " "]]]

["circle 10x10 5 " "circle 20x20 5 " "circle 30x30 5 "]

对此:

[circle 10x10 5 circle 20x20 5 circle 30x30 5]

我想改变它,以便它可以与 VID 一起使用。

view [
      size 800x600
      base 780x580
      draw drawblock
     ]

谢谢!

4

2 回答 2

2

您也可以使用load rejoin转换["set " "of " "spaced " "strings"]

red>> load rejoin ["circle 10x10 5 " "circle 20x20 5 " "circle 30x30 5 "]
== [circle 10x10 5 circle 20x20 5 circle 30x30 5]

最好的办法是一开始就没有字符串块,并尝试尽可能多地使用文字和代码。

编辑:

对于您的特定用例,这将起作用:

drawblock: collect [
    foreach arg [10 20 30] [
        keep compose [circle (as-pair arg arg) 5]
    ]
]

ps如果您正在玩视图这个要点可能会有所帮助

于 2016-09-29T12:51:21.957 回答
2

要转换string!为红色代码,您需要加载它: red>> load "circle 10x10 5 " == [circle 10x10 5]

所以对于string!s 块,只需在循环中加载它们: collect [ foreach arg ["circle 10x10 5 " "circle 20x20 5 " "circle 30x30 5 "] [ keep load arg ] ] == [circle 10x10 5 circle 20x20 5 circle 30x30 5]

但是,对于代码生成,最好直接使用 Red 类型,不要以字符串开头。

于 2016-09-29T12:40:56.773 回答