User talk:Doug Mennella/Trees

From J Wiki
Jump to navigation Jump to search

Igor's edits

Thank you, it is very interesting!

BTW, some comments:

   NB. 1. this line raises an error
   |.&>"0>:@((p{~])^:a:&.>"0) (-.~ i.&#)p
|domain error, executing dyad +
|y is boxed
|   |.&>"0    >:@((p{~])^:a:&.>"0)(-.~i.&#)p

   NB. fix it
   |.&>"0@:((p{~])^:a:&.>"0) (-.~ i.&#)p
0 1 2
0 3 4
0 3 5
0 6 0
   NB. or even better
   |.&> (p{~])^:a:&.> (-.~ i.&#)p
0 1 2
0 3 4
0 3 5
0 6 0
[Comments inline.] Good catch. It looks like I have a bunch of sloppy cut-and-pastes here. I went with |.@((p{~])^:a:)&>"0 (-.~ i.&#)p so that there's only one boxing.
   NB. 2. ls name isn't defined yet
   ls{"1~ |:|.&>"0(p{~])^:a:&.>"0 (-.~ i.&#)p
|index error, executing dyad {"1 1
|index at position 1 3 is 6; too long for axis 1 of y, whose length is only 4
|   ls    {"1~|:|.&>"0(p{~])^:a:&.>"0(-.~i.&#)p

   NB. concise way to define
   ] ls=. ;: 'cat ab u dog hm cat er'
┌───┬──┬─┬───┬──┬───┬──┐
catabudoghmcater
└───┴──┴─┴───┴──┴───┴──┘
Thanks. I'll use this.
   NB. 3. some shagginess here: increment is row-wise
   >:@|.&>(p{~])^:a:&.>"0 (-.~ i.&#)p
1 2 3
1 4 5
1 4 6
1 7 0
   NB. smooth it: increment the whole matrix
   >: |.&> (p{~])^:a:&.> (-.~ i.&#)p
1 2 3
1 4 5
1 4 6
1 7 1
The increment before assembling the result is intentional here. We want the fill to insert 0 for all the positions not representing the 1-index of a node. This is also the reason for the increment, so that it looks different than these filled spots.
   NB. 4. result matches not this but the next sentence
: This was just lazy cut-and-pasting.  I ''think'' I've cleaned it all up but I should give it all a once over.
   NB. in JWiki
   (' ';ls){~"1|:>:@|.&>(p{~])^:a:&.>"0 (-.~ i.&#)p
1 1 1 1
2 4 4 7
3 5 6 0
   NB. the result indeed
┌───┬───┬───┬───┐
│cat│cat│cat│cat│
├───┼───┼───┼───┤
│ab │dog│dog│er │
├───┼───┼───┼───┤
│u  │hm │cat│   │
└───┴───┴───┴───┘
   NB. fix it
   |:>:|.&>(p{~])^:a:&.> (-.~ i.&#)p
1 1 1 1
2 4 4 7
3 5 6 0

   NB. in JWiki
   (' ';ls){~"1|:(***2-.@=/\0,])>:@|.&>(p{~])^:a:&.>"0 (-.~ i.&#)p
1 2 3
0 4 5
0 0 6
0 7 0
   NB. the result indeed
┌───┬───┬───┬──┐
│cat│   │   │  │
├───┼───┼───┼──┤
│ab │dog│   │er│
├───┼───┼───┼──┤
│u  │hm │cat│  │
└───┴───┴───┴──┘
   NB. fix it
   (***2-.@=/\0,])>:|.&>(p{~])^:a:&.> (-.~ i.&#)p
1 2 3
0 4 5
0 0 6
0 7 0
   NB. 5. nodes 2 and 3 are swapped
   NB. in JWiki
   (;/.. i.&#)p
┌─┬───────┐
00 1 2 6
├─┼───────┤
13      
├─┼───────┤
24 5    
└─┴───────┘
   NB. the result indeed
┌─┬───────┐
00 1 3 6
├─┼───────┤
12      
├─┼───────┤
34 5    
└─┴───────┘

   NB. in JWiki
   (<@-.~/.. i.&#)p
┌─────┬─┬───┐
1 2 634 5
└─────┴─┴───┘
   NB. the result indeed
┌─────┬─┬───┐
1 3 624 5
└─────┴─┴───┘

   NB. in JWiki
   ((}:;}.)@-.~/.. i.&#)p
┌───┬───┐
1 22 6
├───┼───┤
      
├───┼───┤
4  5  
└───┴───┘
   NB. the result indeed
┌───┬───┐
1 33 6
├───┼───┤
      
├───┼───┤
4  5  
└───┴───┘

   NB. in JWiki
   |:@;@(<@(}:,"0}.)@-.~/.. i.&#)p
1 2 4
2 6 5
   NB. the result indeed
1 3 4
3 6 5
I changed my example at some point. It looks like I forgot to go back and check the earlier console output.
   NB. 6. columns 2 and 3 are swapped

   NB. in JWiki
   (i.&# e."1 (|:@;@(<@(}:,"0}.)@-.~/.. i.&#)))p
0 1 1 0 1 0 0
0 0 1 0 0 1 1
   NB. the result indeed
0 1 0 1 1 0 0
0 0 0 1 0 1 1

   NB. in JWiki
   (1 2+/@:*i.&# e."1 (|:@;@(<@(}:,"0}.)@-.~/.. i.&#)))p
0 1 3 0 1 2 2
   NB. the result indeed
0 1 0 3 1 2 2

   NB. in JWiki
   ((= i.&#)-~1 2>:@+/@:*i.&# e."1 (|:@;@(<@(}:,"0}.)@-.~/.. i.&#)))p
0 2 4 1 2 3 3
   NB. the result indeed
0 2 1 4 2 3 3
   NB. 7. columns 3 and 4 are swapped

   NB. in JWiki
   (0,1+(= i.&#)-~1 2>:@+/@:*i.&# e."1 (|:@;@(<@(}:,"0}.)@-.~/.. i.&#)))p
0 1 3 5 2 3 4 4
   NB. the result indeed
0 1 3 2 5 3 4 4
   NB. 8. cls name isn't defined yet
   |:@(cls{~"1 tr)p
|value error: cls
|       |:@(cls{~"1 tr)p

"The code in full" section works like a charm. I've stopped at "Centering display" section.

Igor Zhuravlov (talk) 05:11, 13 September 2024 (UTC)


Thanks so much for your feedback! It's certainly motivating to take a closer look at what you've written when you know someone is reading it. :)
I've added comments inline above at this indentation level. Hopefully it's easy to pick them out. I should also consider using syntax highlighting.
I'm sure there are plenty of other Wiki tricks I have yet to learn. Thanks again, and please do let me know if you spot any other errors of find anything unclear.

Doug Mennella (talk) 06:07, 13 September 2024 (UTC)


Ok. I was wrong in item #3, you are right.

Igor Zhuravlov (talk) 06:16, 13 September 2024 (UTC)