Need help with simple problem
I have some blocks which contain other blocks, such as outerBlock: [ ["a" $6.99 [innerBlock1]] ["b" $5.15 [none]] ["c" $8.49 [innerBlock2]] ["d" $6.99 [innerBlock2]] ["e" $6.99 [innerBlock1]] ["f" $5.15 [none]] ] innerBlock2: [ ["aa" $0.00] ["bb" $1.00] ["cc" $2.00] ] innerBlock1: [ ["aaa" $0.50] ["bbb" $1.00] ["ccc" $2.00] ] How do I make it so that the inner blcoks of outerBlock are replaced with their contents, like this outerBlock: [ ["a" $6.99 [["aaa" $0.50]["bbb" $1.00]["ccc" $2.00]]] ["b" $5.15 [none]] ["c" $8.49 [["aa" $0.00]["bb" $1.00]["cc" $2.00]]] ["d" $6.99 [["aa" $0.00]["bb" $1.00]["cc" $2.00]]] ["e" $6.99 [["aaa" $0.50]["bbb" $1.00]["ccc" $2.00]]] ["f" $5.15 [none]] ] When I probe outerBlock, I just get [ ["a" $6.99 [innerBlock1]] ["b" $5.15 [none]] ["c" $8.49 [innerBlock2]] ["d" $6.99 [innerBlock2]] ["e" $6.99 [innerBlock1]] ["f" $5.15 [none]] ] Thanks for any help
posted by: Andrew 27-Oct-2017/19:13:18-7:00
If you can modify your input block, then you could COMPOSE/DEEP though that would require modifying your blocks: compose/deep [ ["a" $6.99 [(innerBlock1)]] ["b" $5.15 [(none)]] ...etc... ] However if you have to stick to the same format, some type of recursive processor is in order. This could be a recursive PARSE rule or a recursive function, such as: resolve-deep: func [values [block!]][ head while [not tail? values][ values: case [ block? values/1 [ resolve-deep values/1 next values ] word? values/1 [ change/part values get values/1 1 ] /else [ next values ] ] ] ]
posted by: Chris 27-Oct-2017/23:34:32-7:00
You can also set it explicitly using 'get: outerBlock/1/3/1: get outerBlock/1/3/1 Do this in a loop to suit your needs.
posted by: Nick 28-Oct-2017/9:33:41-7:00
|