⍝ Bunda-Gerth parsing:

    defns ← scripts._defs           ⍝ alias for definitions in scripts space.

    display defns                   ⍝ definitions:
┌→─────────────────────────────────────────────────────────────────────────────┐
│⍝ Bunda-Gerth definitions for a dfns-like language, in which:                 │
│⍝ - An expression may evaluate to:                                            │
│⍝ - - An Array,                                                               │
│⍝ - - A Function,                                                             │
│⍝ - - An Operator,                                                            │
│⍝ - - A dyadic function bound (curried) with its left argument,               │
│⍝ - - A dyadic operator bound (curried) with its right operand,               │
│⍝ - - A train of arrays and functions with a function as rightmost item.      │
│⍝ - The result of any expression may be named.                                │
│⍝ - Only an Array expression may be guarded.                                  │
│⍝ - A diamond-separated expression list must terminate in an Array expression.│
│                                                                              │
│⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Categories:                         │
│A a b c  0 1 2 3 4 5 6 7 8 9  ⍺ ⍵  #    ⍝ Arrays                              │
│F + - × ÷ ⍳ ⍴ = | ↑ ↓ ⊢ ⊣ ∇             ⍝ Functions                           │
│N x y z                                 ⍝ Names (unassigned).                 │
│H / ⌿ \ ⍀                               ⍝ Hybrid function/operators           │
│AF                                      ⍝ bound left argument                 │
│JOT ∘                                   ⍝ compose / null operand.             │
│DOT .                                   ⍝ ref / product.                      │
│DX                                      ⍝ dotted ...                          │
│MOP ¨ ⍨ &                               ⍝ Monadic operators                   │
│DOP ⍣                                   ⍝ Dyadic operators                    │
│IDX                                     ⍝ index/axis                          │
│XAS                                     ⍝ indexed assignment: [IDX]←          │
│SL  ;                                   ⍝ subscript list  ..;..;..            │
│CLN :                                   ⍝ colon token                         │
│GRD                                     ⍝ guard :                             │
│XL  ⋄                                   ⍝ expression list ..⋄..⋄..            │
│ARO ←                                   ⍝ assignment arrow                    │
│ASG                                     ⍝ name assignment                     │
│ERR                                     ⍝ error                               │
│() [IDX] {F}                            ⍝ brackets                            │
│⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝                                     │
│                                                                              │
│⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Macros:                                             │
│fun=F.H                 ⍝ function                                            │
│rand=A.fun.AF.N         ⍝ operand                                             │
│thing=rand.MOP.DOP.JOT  ⍝ nameable object                                     │
│⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝                                                     │
│                                                                              │
│DX:thing→thing          ⍝ dotted expression.                                  │
│                                                                              │
│A:DOT→DX                ⍝ dotted expression                                   │
│                                                                              │
│  N:ARO→ASG             ⍝ name to assignment arrow                            │
│IDX:ARO→XAS             ⍝ indexed assign ]←                                   │
│                                                                              │
│N:XAS→ASG               ⍝ n[x]←                                               │
│                                                                              │
│A:A→A                   ⍝ array stranding                                     │
│N:N→N                   ⍝ name stranding                                      │
│DOT:A→ERR               ⍝   to prevent #.a+b → #.(a+b)                        │
│                                                                              │
│rand:MOP→F              ⍝ monadic and                                         │
│DOP:rand→MOP            ⍝ ... dyadic operators                                │
│fun:H→F                 ⍝ hybrid as operator                                  │
│DOT:fun→MOP             ⍝ inner product                                       │
│JOT:MOP→F DOP:JOT→MOP   ⍝ jot-as-null: outer product                          │
│JOT:rand→MOP            ⍝ compose                                             │
│rand:IDX→rand           ⍝ axis / index                                        │
│MOP:H→ERR               ⍝   top prevent +¨/¨ → (+¨)(/¨)                       │
│                                                                              │
│A:fun→AF                ⍝ left argument to its function                       │
│IDX:A.fun→ERR           ⍝   to prevent v[0]+1 → v[0](+1)                      │
│                                                                              │
│F.AF:A→A                ⍝ function to its right argument                      │
│                                                                              │
│fun.AF:F→F  F.AF:AF→F   ⍝ function trains                                     │
│                                                                              │
│A.SL:SL→SL SL:A→SL      ⍝ subscript list: [2;] [2;;]                          │
│                                                                              │
│ASG:thing→thing         ⍝ naming leaves / as hybrid                           │
│ASG:DOT→DOP             ⍝ naming fixes  . as product                          │
│                                                                              │
│A:CLN→GRD               ⍝ guard expr is a bool scalar                         │
│GRD:A→A                 ⍝ guard returns an Array.                             │
│CLN:A→ERR               ⍝   to prevent: 1:2⋄ → 1:(2⋄)                         │
│ARO:thing→ERR           ⍝   to prevent a←1⋄2 → a←(1⋄2)                        │
│                                                                              │
│thing.DOT.XL:XL→XL      ⍝ leading side-effect thing-expressions               │
│XL:A→A                  ⍝ expression list returns only an array               │
└──────────────────────────────────────────────────────────────────────────────┘

    defns parse ''                  ⍝ formatted binding matrix:
    ┌─────┬─────┬─────┬─────┬─────┬──────┬─────┬──────┬──────┬────┬──────┬────┬─────┬────┬──────┐
    │A    │F    │N    │H    │AF   │JOT   │DOT  │MOP   │DOP   │IDX │XAS   │SL  │CLN  │XL  │ARO   │
┌───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│A  │9 A  │7 AF │     │7 AF │     │      │12 DX│8 F   │      │8 A │      │4 SL│2 GRD│1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│F  │6 A  │5 F  │     │8 F  │5 F  │      │     │8 F   │      │8 F │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│N  │     │     │9 N  │     │     │      │     │8 F   │      │8 N │10 ASG│    │     │1 XL│11 ASG│
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│H  │     │5 F  │     │8 F  │     │      │     │8 F   │      │8 H │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│AF │6 A  │5 F  │     │     │5 F  │      │     │8 F   │      │8 AF│      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│JOT│8 MOP│8 MOP│8 MOP│8 MOP│8 MOP│      │     │8 F   │      │    │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│DOT│9 ERR│8 MOP│     │8 MOP│     │      │     │      │      │    │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│DX │13 A │13 F │13 N │13 H │13 AF│13 JOT│     │13 MOP│13 DOP│    │      │    │     │    │      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│MOP│     │     │     │8 ERR│     │      │     │      │      │    │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│DOP│8 MOP│8 MOP│8 MOP│8 MOP│8 MOP│8 MOP │     │      │      │    │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│IDX│7 ERR│7 ERR│     │7 ERR│     │      │     │      │      │    │      │    │     │    │11 XAS│
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│SL │4 SL │     │     │     │     │      │     │      │      │    │      │4 SL│     │    │      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│CLN│2 ERR│     │     │     │     │      │     │      │      │    │      │    │     │    │      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│GRD│2 A  │     │     │     │     │      │     │      │      │    │      │    │     │    │      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│XL │1 A  │     │     │     │     │      │     │      │      │    │      │    │     │1 XL│      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│ARO│2 ERR│2 ERR│2 ERR│2 ERR│2 ERR│2 ERR │     │2 ERR │2 ERR │    │      │    │     │    │      │
├───┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼──────┼──────┼────┼──────┼────┼─────┼────┼──────┤
│ASG│3 A  │3 F  │3 N  │3 H  │3 AF │3 JOT │3 DOP│3 MOP │3 DOP │    │      │    │     │    │      │
└───┴─────┴─────┴─────┴─────┴─────┴──────┴─────┴──────┴──────┴────┴──────┴────┴─────┴────┴──────┘

    try ← (0 defns parse'')∘parse               ⍝ parse of expression ⍵.

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Arrays Functions Operators

    try '1+2-3×4÷5'         ⍝ dyadic functions and arrays
    A            
 ┌──┴───┐        
┌┴┐  ┌──┴──┐     
1 + ┌┴┐  ┌─┴──┐  
    2 - ┌┴┐  ┌┴─┐
        3 × ┌┴┐ 5
            4 ÷  

    try '1+-×÷5'            ⍝ monadic functions
   A       
 ┌─┴─┐     
┌┴┐ ┌┴─┐   
1 + - ┌┴─┐ 
      × ┌┴┐
        ÷ 5

    try '+∘ר2+3'           ⍝ operator-function binding
      A      
   ┌──┴───┐  
 ┌─┴──┐  ┌┴─┐
┌┴─┐  ¨ ┌┴┐ 3
+ ┌┴┐   2 +  
  ∘ ×        

    try '+∘-∘×∘÷'           ⍝ operator-operand sequences associate left.
       F     
    ┌──┴───┐ 
 ┌──┴──┐  ┌┴┐
┌┴─┐  ┌┴┐ ∘ ÷
+ ┌┴┐ ∘ ×    
  ∘ -        

    try '+∘2 3'             ⍝ strand binds tighter than dop
 F     
┌┴─┐   
+ ┌┴─┐ 
  ∘ ┌┴┐
    2 3

    try '(2+3)×4'           ⍝ parentheses in array-function sequence.
       A   
     ┌─┴──┐
  ┌──┴──┐ 4
┌─┴─┐   ×  
(  ┌┴─┐    
  ┌┴┐ 3    
  2 +      

    try '+∘(×∘÷)'           ⍝ parentheses in function-operator sequence.
 F         
┌┴─┐       
+ ┌┴─┐     
  ∘ ┌┴─┐   
    ( ┌┴─┐ 
      × ┌┴┐
        ∘ ÷

    try '(+∘×)∘÷'           ⍝ redundant parentheses.
     F     
 ┌───┴───┐ 
┌┴─┐    ┌┴┐
( ┌┴─┐  ∘ ÷
  + ┌┴┐    
    ∘ ×    

    try '(1 2)3+4(5 6)'     ⍝ array stranding
        A        
     ┌──┴──┐     
   ┌─┴──┐ ┌┴─┐   
 ┌─┴──┐ + 4 ┌┴─┐ 
┌┴─┐  3     ( ┌┴┐
( ┌┴┐         5 6
  1 2            

    ⍕try¨ '1 2 3' '(1 2)3' '1(2 3)'     ⍝ stranding distinctions.
   A       A      A      
  ┌┴─┐   ┌─┴──┐  ┌┴─┐    
 ┌┴┐ 3  ┌┴─┐  3  1 ┌┴─┐  
 1 2    ( ┌┴┐      ( ┌┴┐ 
          1 2        2 3 

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Jots 'n Dots

    ⍕try¨ '#.×' '∘.×' '+.×' '+∘÷'   ⍝ jots 'n dots
   F     F      F      F    
  ┌┴─┐  ┌┴─┐   ┌┴─┐   ┌┴─┐  
 ┌┴┐ ×  ∘ ┌┴┐  + ┌┴┐  + ┌┴┐ 
 # .      . ×    . ×    ∘ ÷ 

    try '#.×.∘.+.×∘÷'               ⍝ jot 'n dot medley
              F      
         ┌────┴────┐ 
    ┌────┴─────┐  ┌┴┐
  ┌─┴──┐      ┌┴┐ ∘ ÷
 ┌┴─┐ ┌┴─┐    . ×    
┌┴┐ × . ┌┴─┐         
# .     ∘ ┌┴┐        
          . +        

    ⍕try¨ '(1+)∘(1+)' '(1+)⍣2'      ⍝ monadic function (MF) as operand.
     F              F     
  ┌──┴──┐        ┌──┴──┐  
 ┌┴─┐  ┌┴─┐     ┌┴─┐  ┌┴┐ 
 ( ┌┴┐ ∘ ┌┴─┐   ( ┌┴┐ ⍣ 2 
   1 +   ( ┌┴┐    1 +     
           1 +            

    ⍕try¨ '1+¨' '(1+)¨'             ⍝ test binding difference
  AF       F    
 ┌┴─┐    ┌─┴──┐ 
 1 ┌┴┐  ┌┴─┐  ¨ 
   + ¨  ( ┌┴┐   
          1 +   

    try '⍣∘'                        ⍝ jot-as-null: power limit.
 MOP
┌┴┐ 
⍣ ∘ 

    try '↑⍣∘'                       ⍝ disclose limit.
 F   
┌┴─┐ 
↑ ┌┴┐
  ⍣ ∘

    ⍕try¨ '∘.+' '+∘1'               ⍝ outer product vs. compose
  F      F    
 ┌┴─┐   ┌┴─┐  
 ∘ ┌┴┐  + ┌┴┐ 
   . +    ∘ 1 

    try '# #.a[1]'                  ⍝ strand vs dot vs index.
     A     
  ┌──┴───┐ 
┌─┴─┐   ┌┴┐
#  ┌┴─┐ [ 1
  ┌┴┐ a    
  # .      

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Naming

    try 'x←2 3'                     ⍝ array naming.
   A   
 ┌─┴─┐ 
┌┴┐ ┌┴┐
x ← 2 3

    try 'y←+.×'                     ⍝ function naming.
   F     
 ┌─┴─┐   
┌┴┐ ┌┴─┐ 
y ← + ┌┴┐
      . ×

    try 'z←¨'                       ⍝ mop naming.
  MOP
 ┌┴─┐
┌┴┐ ¨
z ←  

    try 'z←⍣'                       ⍝ dop naming.
  DOP
 ┌┴─┐
┌┴┐ ⍣
z ←  

   ⍕try¨ 'z←∘' 'z←.'                ⍝ jot 'n dot naming.
   JOT    DOP 
  ┌┴─┐   ┌┴─┐ 
 ┌┴┐ ∘  ┌┴┐ . 
 z ←    z ←   

    ⍕try¨ '+(z←∘)÷' '(z←∘).×'       ⍝ naming null/compose.
    F              F      
 ┌──┴───┐       ┌──┴───┐  
 +   ┌──┴──┐  ┌─┴─┐   ┌┴┐ 
   ┌─┴─┐   ÷  (  ┌┴─┐ . × 
   (  ┌┴─┐      ┌┴┐ ∘     
     ┌┴┐ ∘      z ←       
     z ←                  

    try '(x←∘).((y←∘)(z←.)(x←∘))'   ⍝ jot 'n dot naming.
      F                            
  ┌───┴────┐                       
┌─┴─┐   ┌──┴───┐                   
(  ┌┴─┐ . ┌────┴────┐              
  ┌┴┐ ∘   (   ┌─────┴─────┐        
  x ←       ┌─┴─┐     ┌───┴───┐    
            (  ┌┴─┐ ┌─┴─┐   ┌─┴─┐  
              ┌┴┐ ∘ (  ┌┴─┐ (  ┌┴─┐
              y ←     ┌┴┐ .   ┌┴┐ ∘
                      z ←     x ←  

    try 'x y'                       ⍝ name stranding.
 N 
┌┴┐
x y

    try '(x y)←3 4'                 ⍝ struct naming.
      A    
   ┌──┴──┐ 
 ┌─┴──┐ ┌┴┐
┌┴─┐  ← 3 4
( ┌┴┐      
  x y      

    try '(x(y z))←(1 2)3'           ⍝ struct naming.
          A        
     ┌────┴────┐   
 ┌───┴────┐  ┌─┴──┐
┌┴─┐      ← ┌┴─┐  3
( ┌┴─┐      ( ┌┴┐  
  x ┌┴─┐      1 2  
    ( ┌┴┐          
      y z          

    try 'a x←3'                     ⍝ stranding with naming.
  A    
┌─┴─┐  
a  ┌┴─┐
  ┌┴┐ 3
  x ←  

    try '(x←+)(y←/)(z←3)'           ⍝ naming en-passant.
            A          
      ┌─────┴─────┐    
  ┌───┴───┐     ┌─┴─┐  
┌─┴─┐   ┌─┴─┐   (  ┌┴─┐
(  ┌┴─┐ (  ┌┴─┐   ┌┴┐ 3
  ┌┴┐ +   ┌┴┐ /   z ←  
  x ←     y ←          

    try 'x←1:2⋄3'                   ⍝ naming guard condition
          A  
        ┌─┴─┐
      ┌─┴─┐ 3
    ┌─┴─┐ ⋄  
  ┌─┴─┐ 2    
 ┌┴─┐ :      
┌┴┐ 1        
x ←          

    try 'x←(1:2⋄3)'                 ⍝ naming guard expression
    A          
 ┌──┴───┐      
┌┴┐ ┌───┴───┐  
x ← (     ┌─┴─┐
        ┌─┴─┐ 3
       ┌┴─┐ ⋄  
      ┌┴┐ 2    
      1 :      

    ⍕try¨ '1(z←/)¨2' '+(z←/)¨2'     ⍝ naming retains hybrid behaviour
        A                A    
    ┌───┴────┐        ┌──┴──┐ 
 ┌──┴───┐    2    ┌───┴───┐ 2 
 1   ┌──┴──┐    ┌─┴─┐     ¨   
   ┌─┴─┐   ¨    + ┌─┴─┐       
   (  ┌┴─┐        (  ┌┴─┐     
     ┌┴┐ /          ┌┴┐ /     
     z ←            z ←       

    ⍕try¨ 'z←'∘,¨ '0+/¨⍣∘.'         ⍝ naming of each category
   A      F      H      MOP    DOP    JOT    DOP 
  ┌┴─┐   ┌┴─┐   ┌┴─┐   ┌┴─┐   ┌┴─┐   ┌┴─┐   ┌┴─┐ 
 ┌┴┐ 0  ┌┴┐ +  ┌┴┐ /  ┌┴┐ ¨  ┌┴┐ ⍣  ┌┴┐ ∘  ┌┴┐ . 
 z ←    z ←    z ←    z ←    z ←    z ←    z ←   

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Hybrids

    ⍕try¨ '+/¨0' '1/¨0'             ⍝ hybrids: defining example.
     A       A    
   ┌─┴─┐   ┌─┴──┐ 
  ┌┴─┐ 0  ┌┴─┐  0 
 ┌┴┐ ¨    1 ┌┴┐   
 + /        / ¨   

    ⍕try¨ '/./' '/∘/'               ⍝ hybrids, jots 'n dots
  F      F    
 ┌┴─┐   ┌┴─┐  
 / ┌┴┐  / ┌┴┐ 
   . /    ∘ / 

    try 'x←↑(//)(1 2)(3 4)'         ⍝ replication-reduction
    A                  
 ┌──┴──┐               
┌┴┐ ┌──┴───┐           
x ← ↑  ┌───┴────┐      
      ┌┴─┐   ┌──┴──┐   
      ( ┌┴┐ ┌┴─┐  ┌┴─┐ 
        / / ( ┌┴┐ ( ┌┴┐
              1 2   3 4

    try 'z←//'                      ⍝ ← doesn't bind with /
   F   
 ┌─┴─┐ 
┌┴┐ ┌┴┐
z ← / /

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Guards & Diamonds

    try '⍺=0: ⍵+1'                  ⍝ guard.
       A     
    ┌──┴──┐  
  ┌─┴─┐  ┌┴─┐
 ┌┴─┐ : ┌┴┐ 1
┌┴┐ 0   ⍵ +  
⍺ =          

    try '0 ⋄ 1 ⋄ 2 ⋄ 3'             ⍝ diamond segments.
          A  
        ┌─┴─┐
      ┌─┴─┐ 3
    ┌─┴─┐ ⋄  
  ┌─┴─┐ 2    
 ┌┴─┐ ⋄      
┌┴┐ 1        
0 ⋄          

    try '0:0+0 ⋄ 0:1+1 ⋄ 0:2+2 ⋄ 3' ⍝ guarded segments.
                               A     
                           ┌───┴────┐
                     ┌─────┴──────┐ 3
                ┌────┴─────┐      ⋄  
          ┌─────┴─────┐  ┌─┴──┐      
      ┌───┴────┐      ⋄ ┌┴┐  ┌┴─┐    
   ┌──┴───┐  ┌─┴──┐     0 : ┌┴┐ 2    
 ┌─┴──┐   ⋄ ┌┴┐  ┌┴─┐       2 +      
┌┴┐  ┌┴─┐   0 : ┌┴┐ 1                
0 : ┌┴┐ 0       1 +                  
    0 +                              

    try '(z←+ ⋄ 1+2)+3'             ⍝ leading non-array segment.
              A    
          ┌───┴───┐
    ┌─────┴─────┐ 3
┌───┴────┐      +  
(     ┌──┴──┐      
    ┌─┴─┐  ┌┴─┐    
   ┌┴─┐ ⋄ ┌┴┐ 2    
  ┌┴┐ +   1 +      
  z ←              

    dmd ← ' ⋄ ⋄ ' ' ⋄ ⋄2' ' ⋄1⋄ ' ' ⋄1⋄2'
    dmd,← '0⋄ ⋄ ' '0⋄ ⋄2' '0⋄1⋄ ' '0⋄1⋄2'

    try¨ 2 4⍴ dmd                   ⍝ expression lists
┌─────┬───────┬───────┬─────────┐
│ XL  │  A    │  XL   │    A    │
│┌┴┐  │ ┌┴─┐  │ ┌┴─┐  │  ┌─┴─┐  │
│⋄ ⋄  │┌┴┐ 2  │┌┴┐ ⋄  │ ┌┴─┐ 2  │
│     │⋄ ⋄    │⋄ 1    │┌┴┐ ⋄    │
│     │       │       │⋄ 1      │
├─────┼───────┼───────┼─────────┤
│  XL │    A  │    XL │      A  │
│ ┌┴─┐│  ┌─┴─┐│  ┌─┴─┐│    ┌─┴─┐│
│┌┴┐ ⋄│ ┌┴─┐ 2│ ┌┴─┐ ⋄│  ┌─┴─┐ 2│
│0 ⋄  │┌┴┐ ⋄  │┌┴┐ 1  │ ┌┴─┐ ⋄  │
│     │0 ⋄    │0 ⋄    │┌┴┐ 1    │
│     │       │       │0 ⋄      │
└─────┴───────┴───────┴─────────┘

    try¨ '0+/¨⍣∘.' ,¨⊂'⋄0'          ⍝ expression lists
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│  A  │  A  │  A  │  A  │  A  │  A  │  A  │
│ ┌┴─┐│ ┌┴─┐│ ┌┴─┐│ ┌┴─┐│ ┌┴─┐│ ┌┴─┐│ ┌┴─┐│
│┌┴┐ 0│┌┴┐ 0│┌┴┐ 0│┌┴┐ 0│┌┴┐ 0│┌┴┐ 0│┌┴┐ 0│
│0 ⋄  │+ ⋄  │/ ⋄  │¨ ⋄  │⍣ ⋄  │∘ ⋄  │. ⋄  │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ axis and index

    idx ← '[ ;;]' '[ ;;3]' '[ ;2;]' '[ ;2;3]'   ⍝ subscripts
    idx,← '[1;;]' '[1;;3]' '[1;2;]' '[1;2;3]'

    try¨ 2 4⍴ idx                   ⍝ subscript lists
┌───────┬─────────┬─────────┬───────────┐
│ IDX   │  IDX    │  IDX    │   IDX     │
│┌┴─┐   │┌─┴─┐    │┌─┴─┐    │┌──┴──┐    │
│[ ┌┴┐  │[  ┌┴─┐  │[  ┌┴─┐  │[   ┌─┴─┐  │
│  ; ;  │  ┌┴┐ 3  │  ┌┴┐ ;  │   ┌┴─┐ 3  │
│       │  ; ;    │  ; 2    │  ┌┴┐ ;    │
│       │         │         │  ; 2      │
├───────┼─────────┼─────────┼───────────┤
│  IDX  │   IDX   │   IDX   │    IDX    │
│┌─┴─┐  │┌──┴──┐  │┌──┴──┐  │┌───┴───┐  │
│[  ┌┴─┐│[   ┌─┴─┐│[   ┌─┴─┐│[     ┌─┴─┐│
│  ┌┴┐ ;│   ┌┴─┐ 3│   ┌┴─┐ ;│    ┌─┴─┐ 3│
│  1 ;  │  ┌┴┐ ;  │  ┌┴┐ 2  │   ┌┴─┐ ;  │
│       │  1 ;    │  1 ;    │  ┌┴┐ 2    │
│       │         │         │  1 ;      │
└───────┴─────────┴─────────┴───────────┘

    ⍕try¨ '()' '[]' '{}'            ⍝ empty brackets
 ┌─┬─┐  IDX  F 
 │(│)│  [    { 
 └─┴─┘         

    ⍕try¨ '⍵[;;]' '⍵[;]' '⍵[]'      ⍝ decreasing rank
  A        A      A  
 ┌┴─┐     ┌┴─┐   ┌┴┐ 
 ⍵ ┌┴─┐   ⍵ ┌┴┐  ⍵ [ 
   [ ┌┴┐    [ ;      
     ; ;             

    try 'a[1][2][3]'                ⍝ contiguous IDXs.
       A     
    ┌──┴───┐ 
 ┌──┴──┐  ┌┴┐
┌┴─┐  ┌┴┐ [ 3
a ┌┴┐ [ 2    
  [ 1        

    try 'x[2]←0'                    ⍝ indexed assignment
     A   
  ┌──┴──┐
┌─┴─┐   0
x  ┌┴─┐  
  ┌┴┐ ←  
  [ 2    

    try '[0]←'                      ⍝ partial indexed assignment
  XAS
 ┌┴─┐
┌┴┐ ←
[ 0  

    try 'a x[2]←0'                  ⍝ stranding with indexed assignment.
   A       
┌──┴───┐   
a   ┌──┴──┐
  ┌─┴─┐   0
  x  ┌┴─┐  
    ┌┴┐ ←  
    [ 2    

    try '(x y)[0]←1'                ⍝ selective assignment.
        A    
    ┌───┴───┐
 ┌──┴───┐   1
┌┴─┐   ┌┴─┐  
( ┌┴┐ ┌┴┐ ←  
  x y [ 0    

    try '1/[0]⍵'                    ⍝ hybrid-fn axis
    A    
 ┌──┴───┐
┌┴─┐    ⍵
1 ┌┴─┐   
  / ┌┴┐  
    [ 0  

    try '+/[0]⍵'                    ⍝ derived-fn axis
     A   
   ┌─┴──┐
 ┌─┴─┐  ⍵
┌┴┐ ┌┴┐  
+ / [ 0  

    try '2+/[0]⍵'                   ⍝ dyadic derived-fn axis
      A    
  ┌───┴───┐
┌─┴──┐    ⍵
2  ┌─┴─┐   
  ┌┴┐ ┌┴┐  
  + / [ 0  

    try '(1/)[0]⍵'                  ⍝ AF with axis
       A   
    ┌──┴──┐
 ┌──┴──┐  ⍵
┌┴─┐  ┌┴┐  
( ┌┴┐ [ 0  
  1 /      

   ⍕try¨ '⍵[1]' '+[1]' 'z[1]'       ⍝ array, function, name
  A      F      N    
 ┌┴─┐   ┌┴─┐   ┌┴─┐  
 ⍵ ┌┴┐  + ┌┴┐  z ┌┴┐ 
   [ 1    [ 1    [ 1 

    try '{+/[0]⍵}(2 3⍴⍳4)[;0]'      ⍝ parentheses, brackets and braces.
           A                 
   ┌───────┴────────┐        
┌──┴───┐       ┌────┴────┐   
{    ┌─┴──┐ ┌──┴──┐     ┌┴─┐ 
   ┌─┴─┐  ⍵ (   ┌─┴──┐  [ ┌┴┐
  ┌┴┐ ┌┴┐      ┌┴─┐ ┌┴┐   ; 0
  + / [ 0     ┌┴┐ ⍴ ⍳ 4      
              2 3            

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Function trains

    try '+-×÷'                      ⍝ function train.
    F  
  ┌─┴─┐
 ┌┴─┐ ÷
┌┴┐ ×  
+ -    

    try '1+÷'                       ⍝ Agh train
  F  
 ┌┴─┐
┌┴┐ ÷
1 +  

    try '÷1+'                       ⍝ fBh train
 F   
┌┴─┐ 
÷ ┌┴┐
  1 +

    try '1+3×'                      ⍝ A(fBh)
   F   
 ┌─┴─┐ 
┌┴┐ ┌┴┐
1 + 3 ×

    try '1+2-3×4÷'                  ⍝ longer (A:F)* train
         F     
      ┌──┴───┐ 
   ┌──┴──┐  ┌┴┐
 ┌─┴─┐  ┌┴┐ 4 ÷
┌┴┐ ┌┴┐ 3 ×    
1 + 2 -        

    try '+/÷⍴'                      ⍝ train for vector mean
    F  
  ┌─┴─┐
 ┌┴─┐ ⍴
┌┴┐ ÷  
+ /    

    try '/∘⊢'                       ⍝ fix / as replicate function
 F   
┌┴─┐ 
/ ┌┴┐
  ∘ ⊢

    ⍕try¨ '+/×' '+(/∘⊢)×'           ⍝ 2-train vs 3-train
   F         F      
  ┌┴─┐   ┌───┴────┐ 
 ┌┴┐ ×  ┌┴─┐      × 
 + /    + ┌┴─┐      
          ( ┌┴─┐    
            / ┌┴┐   
              ∘ ⊢   

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Miscellaneous

    try '∘'                         ⍝ single token.
JOT
∘  

    ⍕try¨ ∘.,⍨ '#=⍨⍣∘.'             ⍝ not all pairs bind:
  A        AF       F         ┌─┬───┐    ┌─┬───┐     DX       
 ┌┴┐      ┌┴┐      ┌┴┐        │A│DOP│    │A│JOT│    ┌┴┐       
 # #      # =      # ⍨        │#│⍣  │    │#│∘  │    # .       
                              └─┴───┘    └─┴───┘              
  A        F        F         ┌─┬───┐    ┌─┬───┐    ┌─┬───┐   
 ┌┴┐      ┌┴┐      ┌┴┐        │F│DOP│    │F│JOT│    │F│DOT│   
 = #      = =      = ⍨        │=│⍣  │    │=│∘  │    │=│.  │   
                              └─┴───┘    └─┴───┘    └─┴───┘   
 ┌───┬─┐  ┌───┬─┐  ┌───┬───┐  ┌───┬───┐  ┌───┬───┐  ┌───┬───┐ 
 │MOP│A│  │MOP│F│  │MOP│MOP│  │MOP│DOP│  │MOP│JOT│  │MOP│DOT│ 
 │⍨  │#│  │⍨  │=│  │⍨  │⍨  │  │⍨  │⍣  │  │⍨  │∘  │  │⍨  │.  │ 
 └───┴─┘  └───┴─┘  └───┴───┘  └───┴───┘  └───┴───┘  └───┴───┘ 
  MOP      MOP     ┌───┬───┐  ┌───┬───┐   MOP       ┌───┬───┐ 
 ┌┴┐      ┌┴┐      │DOP│MOP│  │DOP│DOP│  ┌┴┐        │DOP│DOT│ 
 ⍣ #      ⍣ =      │⍣  │⍨  │  │⍣  │⍣  │  ⍣ ∘        │⍣  │.  │ 
                   └───┴───┘  └───┴───┘             └───┴───┘ 
  MOP      MOP      F         ┌───┬───┐  ┌───┬───┐  ┌───┬───┐ 
 ┌┴┐      ┌┴┐      ┌┴┐        │JOT│DOP│  │JOT│JOT│  │JOT│DOT│ 
 ∘ #      ∘ =      ∘ ⍨        │∘  │⍣  │  │∘  │∘  │  │∘  │.  │ 
                              └───┴───┘  └───┴───┘  └───┴───┘ 
  ERR      MOP     ┌───┬───┐  ┌───┬───┐  ┌───┬───┐  ┌───┬───┐ 
 ┌┴┐      ┌┴┐      │DOT│MOP│  │DOT│DOP│  │DOT│JOT│  │DOT│DOT│ 
 . #      . =      │.  │⍨  │  │.  │⍣  │  │.  │∘  │  │.  │.  │ 
                   └───┴───┘  └───┴───┘  └───┴───┘  └───┴───┘ 

    try '()'                        ⍝ null expression: error.
┌─┬─┐
│(│)│
└─┴─┘

    try '(((3)))'                   ⍝ deep parentheses.
 A     
┌┴─┐   
( ┌┴─┐ 
  ( ┌┴┐
    ( 3

    try '#.a #.(b+1) #.#.c + 2'     ⍝ lotsa dots.
                         A     
                    ┌────┴────┐
             ┌──────┴───────┐ 2
     ┌───────┴───────┐      +  
  ┌──┴───┐         ┌─┴──┐      
 ┌┴─┐  ┌─┴──┐     ┌┴┐  ┌┴─┐    
┌┴┐ a ┌┴┐ ┌─┴─┐   # . ┌┴┐ c    
# .   # . (  ┌┴─┐     # .      
            ┌┴┐ 1              
            b +                

    try '{⍵=1:1 ⋄ 2|⍵:∇ 1+3×⍵ ⋄ ∇ ⍵÷2}'     ⍝ →osc← function
               F                           
┌──────────────┴───────────────┐           
{                       ┌──────┴──────┐    
               ┌────────┴─────────┐ ┌─┴─┐  
          ┌────┴─────┐            ⋄ ∇  ┌┴─┐
        ┌─┴─┐     ┌──┴──┐             ┌┴┐ 2
      ┌─┴─┐ ⋄   ┌─┴─┐ ┌─┴──┐          ⍵ ÷  
    ┌─┴─┐ 1    ┌┴─┐ : ∇  ┌─┴──┐            
   ┌┴─┐ :     ┌┴┐ ⍵     ┌┴┐  ┌┴─┐          
  ┌┴┐ 1       2 |       1 + ┌┴┐ ⍵          
  ⍵ =                       3 ×            

    try 'x←3 4⍴⍳5 ⋄ #.a ∘.+ b[⍳3;] +.× ∘.{(+/⍵)÷⍴⍵}⍨ c'     ⍝ complex expression
                     A                                             
         ┌───────────┴───────────┐                                 
    ┌────┴────┐     ┌────────────┴─────────────┐                   
 ┌──┴───┐     ⋄   ┌─┴──┐          ┌────────────┴────────────┐      
┌┴┐   ┌─┴──┐     ┌┴─┐ ┌┴─┐    ┌───┴────┐               ┌────┴─────┐
x ←  ┌┴─┐ ┌┴┐   ┌┴┐ a ∘ ┌┴┐ ┌─┴─┐     ┌┴─┐    ┌────────┴────────┐ c
    ┌┴┐ ⍴ ⍳ 5   # .     . + b ┌─┴─┐   + ┌┴┐ ┌─┴──┐              ⍨  
    3 4                       [  ┌┴─┐   . × ∘ ┌──┴───┐             
                                ┌┴┐ ;         . ┌────┴────┐        
                                ⍳ 3             {      ┌──┴──┐     
                                                    ┌──┴──┐ ┌┴┐    
                                                  ┌─┴─┐   ÷ ⍴ ⍵    
                                                  (  ┌┴─┐          
                                                    ┌┴┐ ⍵          
                                                    + /            

Back to: code

Back to: Workspaces