Home   Archive   Permalink



How do you append blocks to a block?

Hello,
    
Suppose you have a block, lol: [1 2 3]. How can you add to that block to make it lol: [1 [1 2 3] 2 [2 3 1] 3 [3 1 2]] ?

posted by:   Andrew     12-Jul-2017/17:01:19-7:00



The magic refinement to keep a block as a block when adding it to a block is /ONLY
    
lol: copy [1 2 3]
insert/only at lol 2 [1 2 3]
insert/only at lol 4 [2 3 1]
append/only lol [3 1 2]
probe lol
== [1 [1 2 3] 2 [2 3 1] 3 [3 1 2]]

posted by:   Sunanda     12-Jul-2017/19:13:05-7:00



In some cases, you may also want to use 'reduce to form nested blocks directly:
    
x: [1 2 3]
y: [2 3 1]
z: [3 1 2]
lol: reduce [1 x 2 y 3 z]
== [1 [1 2 3] 2 [2 3 1] 3 [3 1 2]]


posted by:   Nick     14-Jul-2017/0:11:59-7:00



And to build on Sunanda's example a bit:
    
lol: copy [1 2 3]
x: copy [[1 2 3][2 3 1][3 1 2]]
repeat i length? lol [insert/only at lol i * 2 x/:i]
lol
== [1 [1 2 3] 2 [2 3 1] 3 [3 1 2]]

posted by:   Nick     14-Jul-2017/0:25:21-7:00