⍝ defs:

    :ReturnIf 3≠ ⎕nc'⎕SE.Dyalog.Utils.repObj'   ⍝ required library function

    ⎕ex'Alpha'                                  ⍝ remove alias for 1
    ⎕ex ~∘'defs' 'disp' ~∘' '¨ ↓⎕nl 3 4         ⍝ declutter for speed

     avg ← (sum←(plus←+)(fold←⌿)) ÷ (num←≢)     ⍝ some definitions ...
    davg ← {(sum÷num)⍵}
     dup ← {⍵ ⍵}
    each ← {⍺←⊢ ⋄ ⍺ ⍺⍺¨⍵}
    dups ← dup each
    same ← (succ←one∘plus)∘(pred←-∘(one←1))
   isnum ← ∊∘(digs←'0123456789')
   twice ← {⍺⍺ ⍺⍺ ⍵}
   greet ← 'hello'twice

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Listing with names

    1 defs ''                       ⍝ all defns
  avg ← sum÷num       
 davg ← {(sum÷num)⍵}  
 digs ← '0123456789'  
  dup ← {⍵ ⍵}         
 dups ← dup each      
 each ← {⍺←⊢ ⋄ ⍺ ⍺⍺¨⍵}
 fold ← ⌿             
greet ← 'hello'twice  
isnum ← ∊∘digs        
  num ← ≢             
  one ← 1             
 plus ← +             
 pred ← -∘one         
 same ← succ∘pred     
 succ ← one∘plus      
  sum ← plus fold     
twice ← {⍺⍺ ⍺⍺ ⍵}     

    1 defs 'same'                   ⍝ "same" with names
same ← succ∘pred

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Bottom-up dependencies:

    1 ¯1 defs 'plus'                ⍝ defns dependent on "plus"
plus ← +        
 sum ← plus fold
 avg ← sum÷num  
succ ← one∘plus 
same ← succ∘pred

    1 ¯1 defs 'plus' 'one'          ⍝ defns dependent on "plus" and "one"
plus ← +        
 sum ← plus fold
 avg ← sum÷num  
 one ← 1        
succ ← one∘plus 
pred ← -∘one    
same ← succ∘pred

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Top-down indented display:

    1 1 defs 'avg'                  ⍝ top-down defns of "avg"
avg ← sum÷num    
  sum ← plus fold
    plus ← +     
    fold ← ⌿     
  num ← ≢        

    1 1 defs ''                     ⍝ top-down defns
avg ← sum÷num          
  sum ← plus fold      
    plus ← +           
    fold ← ⌿           
  num ← ≢              
davg ← {(sum÷num)⍵}    
dups ← dup each        
  dup ← {⍵ ⍵}          
  each ← {⍺←⊢ ⋄ ⍺ ⍺⍺¨⍵}
greet ← 'hello'twice   
  twice ← {⍺⍺ ⍺⍺ ⍵}    
isnum ← ∊∘digs         
  digs ← '0123456789'  
same ← succ∘pred       
  succ ← one∘plus      
    one ← 1            
  pred ← -∘one         

    at←{⍵+(⍴⍵)↑(-⍺⍺)↑⍺}             ⍝ some dfns
    avl←{(⍳×/1↓⍴⍵)~⍵×⊃⍺⌷⍺⍺}
    box←{⍵⌿⍵/⍵ ⍵⍴⍳⍵×⍵}
    cmap←{⊂[⍳⍴⍴⍵]1∊¨⍵∘.=⍵}
    emt←{(,⍵=0)/,⍳⍴⍵}
    nxt←{(⍺(⍺⍺ avl)⍵)(⍺ at)¨⊂⍵}
    nxtv←{⊃,/⍺∘(⍺⍺ nxt)¨⍵}
    rcb←{(⍳⍵),¨box⊃⍵*÷2}
    sfmt←{⊂[3 4]1 3 2 4⍉(2/(⍴⍵)*÷2)⍴⍵}
    sudoku←{sfmt⊃cmap∘rcb svec ⍵}
    svec←{⊃(⍺⍺⍴⍵)nxtv/(emt ⍵),⊂⊂⍵}

    1 1 defs 'sudoku'
sudoku ← {sfmt⊃cmap∘rcb svec ⍵}       
  sfmt ← {⊂[3 4]1 3 2 4⍉(2/(⍴⍵)*÷2)⍴⍵}
  cmap ← {⊂[⍳⍴⍴⍵]1∊¨⍵∘.=⍵}            
  rcb ← {(⍳⍵),¨box⊃⍵*÷2}              
    box ← {⍵⌿⍵/⍵ ⍵⍴⍳⍵×⍵}              
  svec ← {⊃(⍺⍺⍴⍵)nxtv/(emt ⍵),⊂⊂⍵}    
    nxtv ← {⊃,/⍺∘(⍺⍺ nxt)¨⍵}          
      nxt ← {(⍺(⍺⍺ avl)⍵)(⍺ at)¨⊂⍵}   
        avl ← {(⍳×/1↓⍴⍵)~⍵×⊃⍺⌷⍺⍺}     
        at ← {⍵+(⍴⍵)↑(-⍺⍺)↑⍺}         
    emt ← {(,⍵=0)/,⍳⍴⍵}               

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ changing definitions:

    1 ¯1 defs 'plus ← -∘-'          ⍝ verbose change of "plus"
plus ← -∘-      
 sum ← plus fold
 avg ← sum÷num  
succ ← one∘plus 
same ← succ∘pred

    0 defs 'same'                   ⍝ change to "plus" has changed "same"
same ← 1∘(-∘-)∘(-∘1)

    defs 'plus ← +'                 ⍝ quiet change of "plus"

    0 defs 'same'                   ⍝ change to "plus" has changed "same"
same ← 1∘+∘(-∘1)

Back to: code

Back to: Workspaces