Kip Murray
>   I thought if I had a good 
>  tree display I could begin to understand L. and L: .  Kip

Two notes.  

One, trees and their display have a long history in J and APL, all the way
back to "A Programming Language" in 1962 [1].  See, for example  
http://portal.acm.org/citation.cfm?doid=166197.166231  which contains many
utilities for representing and displaying trees in J, and reads, in part:

  This work had its origin in a desire to include trees in APL
  systems. Although Iverson’s early book [Iv62] dwells at
  great length on trees as data structures, APL
  implementations have not provided them as a data type.
  One reason for the omission was that tree structures in all
  the referenced works are flat trees: the analogy in nature is
  the highly artificial espalier, or tree forced against a wall.
  Iverson envisions trees as round at each node; the dispersion
  to other nodes may occur in any directiow which is to say,
  with any rank and shape [Iv92]. Such rounded trees maybe
  viewed as the general case, which leaves the familiar flat
  trees as a subset.
  
which, as you can see, anticipates your (and Raul's) questions about
multidimensional and nested trees.   If you're really interested, look
through the paper's citations.

Second note:  

           tree =: 5!:4
           
           tree {.;:'toJ'
                 +- 10{a.                               
                 |                   +- I.              
                 |             +- @ -+          +- e.   
               +-+- } ----- @ -+     +- & ------+- 13{a.
               | |             +- ]                     
               | +- ]                                   
        -- @: -+                                        
               | +- ~ ----- #                           
               | |                                      
               +-+       +- -.                          
                 |       |           +- 13 10{a.        
                 +- @ ---+     +- & -+- E.              
                         +- @ -+- ,                                   
      
I don't think it'd be difficult to adapt  5!:4  to nouns (though displaying
the values of the nouns might be troublesome).

By the way,  L.  and  L:  are easy to understand in terms of boxes; you
don't need trees.  An open array (an array that matches its open) has a
depth of zero (0 = L.) .  A boxed array has depth one greater than the
maximum depth of its atoms (L. = 1 + >./@:,@:(L.&>)).  

Within the nested contents of a boxed array, a box with a particular depth
D is said to be at "level D".  You can apply a verb at level D (that is,
to all the nested contents of a boxed array which have depth D) with  verb
L: D  .  That could be phrased as "apply  verb  D levels up from the
bottom".

Negative levels are complementary; if  10=L.y  then  verb L: _3 y  is
equivalent to  verb L: 7 y  .  The temptation is to think of level -D as
"D levels down from the top", so that e.g.  verb L: _3  would be the same
as  verb&.>&.>&.>  .  But that's not the case.  This can be frustrating;
there really is no good shortcut for  verb&.>&.>&.>  .

-Dan

[1]  Devon wrote up a small treatment of trees from "A Programming
Language" on the wiki:
     http://www.jsoftware.com/jwiki/DevonMcCormick/APLTree

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to