A version that is probably faster as it is not recursive,
hook =: 2 : '([: u v) : (u v) '
amendT =: 2 : ' u hook (n { ]) n} ]'
joinB =: 1 : ' ((- # m)&}.@;@(,&m&.>"1))'(@:(] :;))
uf2 =: 1 : ' '' each amendT '' joinB ": each ''[''; |. m '
uf =: 1 : '''x &'' , m uf2 ,'' y'''(4 :)
(2;1;1)uf
4 : 'x &[ each amendT 1 each amendT 1 each amendT 2 y'
'Matt' (2;1;1)uf 'the cat';'sat';<'on';<('the';'mat')
┌───────┬───┬───────────────┐
│the cat│sat│┌──┬──────────┐│
│ │ ││on│┌───┬────┐││
│ │ ││ ││the│Matt│││
│ │ ││ │└───┴────┘││
│ │ │└──┴──────────┘│
└───────┴───┴───────────────┘
an applyintree version that returns a tacit verb, though dyads often result in
rank errors
eval =: 1 : ' a: 1 : m'
ait =: (2 :' ('' each amendT '' joinB ": each u lrA ; |. n ) eval ')
toupper ait (2;1;1) NB. returns long tacit verb
toupper ait(2;1;1)'the cat';'sat';<'on';<('the';'mat')
┌───────┬───┬──────────────┐
│the cat│sat│┌──┬─────────┐│
│ │ ││on│┌───┬───┐││
│ │ ││ ││the│MAT│││
│ │ ││ │└───┴───┘││
│ │ │└──┴─────────┘│
└───────┴───┴──────────────┘
'Fat' [ ait(2;1;1)'the cat';'sat';<'on';<('the';'mat')
|rank error
but these are ok:
'F' [ ait(2;1;1)'the cat';'sat';<'on';<('the';'mat')
'Fat'&, ait(2;1;1)'the cat';'sat';<'on';<('the';'mat')
----- Original Message -----
From: Jose Mario Quintana <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Sunday, November 16, 2014 12:51 PM
Subject: Re: [Jprogramming] Setting arbitrary leaf of tree
Pascal wrote:
> Maybe this answers your question about dyadic use:
It is very helpful. My question was open-ended and you partially answered
it; thanks a lot. I posed the question in the first place because Thomas
and I have occasionally entertained the possibility of implementing, in a
Jx interpreter, a version of }:: (even if it is only done for having a
sense of completeness; a http://www.jsoftware.com/forumsearch for }::
returns 44 hits so far). Henry's applyintree conjunction could be a model
for it but we do not fully understand it; see also Thomas's comment in the
message
http://www.jsoftware.com/pipermail/programming/2013-August/033229.html . I
guess we will have to wait for Henry or someone else to update NuVoc as he
suggested.
There another reason to be cautious about the design; apparently }:: was
(is?) meant to be an adverb,
JVERSION
Installer: j602a_win.exe
Engine: j701/2011-01-10/11:25
Library: 6.02.023
a0=. }::
type'a0'
┌──────┐
│adverb│
└──────┘
On Fri, Nov 14, 2014 at 8:20 PM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:
> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm