that is a cool function. Similar to Raul's
for those who had problems copying it:
applyintree =: 2 : 0
if. #n do. ((u applyintree (}.n)) L:_1 ({.n){y) ({.n)} y else. u y end.
:
NB. The rank is s,0 where s is the surplus of x-rank over y-rank. This causes
NB. the cells of y to be matched up with the largest appropriate blocks x.
This
NB. is necessary because it is impossible to change the shape of the values
being modified
if. #n do. (x u applyintree (}.n) L:_ _1"(0 (,~ >.) x -&(#@$) a) (a =.
({.n){y)) ({.n)} y
else. x u y end.
)
Maybe this answers your question about dyadic use:
1 + applyintree 1 <"0 i.2 3
┌─┬─┬─┐
│0│1│2│
├─┼─┼─┤
│4│5│6│
└─┴─┴─┘
1 + (applyintree 1)"1 <"0 i.2 3
┌─┬─┬─┐
│0│2│2│
├─┼─┼─┤
│3│5│5│
└─┴─┴─┘
1 2 + (applyintree 1)"1 <"0 i.2 3
┌─┬───┬─┐
│0│2 3│2│
├─┼───┼─┤
│3│5 6│5│
└─┴───┴─┘
1 2 + (applyintree 1)"_1 <"0 i.2 3
┌─┬─┬─┐
│0│2│2│
├─┼─┼─┤
│3│6│5│
└─┴─┴─┘
1 2 3 + (applyintree 1) <"0 i.2 3
┌─┬─┬─┐
│0│1│2│
├─┼─┼─┤
│4│6│8│
└─┴─┴─┘
1 2&+ (applyintree 1) <"0 i.2 3
┌───┬───┬───┐
│0 │1 │2 │
├───┼───┼───┤
│4 5│5 6│6 7│
└───┴───┴───┘
----- Original Message -----
From: Jose Mario Quintana <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Friday, November 14, 2014 6:33 PM
Subject: Re: [Jprogramming] Setting arbitrary leaf of tree
This subject has been discussed many times in the forum; see, for example,
http://www.jsoftware.com/pipermail/programming/2013-August/033228.html
By the way, I am still wondering about the answer to my question in that
message.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm