Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. cmp←{ ⍝ compare basic arrays, results in ¯1 (⍺ precedes ⍵), 0 (⍺ is identical to ⍵), or 1 (⍺ follows ⍵)
  2.  
  3. ⍝ DEFINITION:
  4. ⍝ ┌
  5. ⍝ │ ¯1 if ⍺ strictly precedes ⍵
  6. ⍝ ⍺ cmp ⍵ = │ 0 if ⍺ exactly matches ⍵
  7. ⍝ │ 1 if ⍺ strictly follows ⍵
  8. ⍝ └
  9.  
  10. ⍝ AXIOMS:
  11. ⍝ 1. exact comparisons, ⎕UCS for characters
  12. ⍝ 2. result is first non-zero in ravel order
  13. ⍝ 3. complex numbers have imaginary part as additional dimension after real part
  14. ⍝ 4. numbers precede characters
  15. ⍝ 5. dictionary order: "nothing precedes something", break ties by comparing shape
  16. ⍝ 6. visual fidelity: extend with leading 1-axes, break ties by comparing rank
  17.  
  18. Ö←{(⍵⍵ ⍺)⍺⍺(⍵⍵ ⍵)} ⍝ Over operator
  19.  
  20. ⎕CT←⎕DCT←0 ⋄ ⎕FR←1287 ⍝ Axiom 1: exact or as exact as possible
  21.  
  22. ⍺{11::0 ⋄ ⍺≡⍵}⍵:0 ⍝ Definition: exact match (trap DECF vs xomplex)
  23.  
  24. ⍺>Ö(0∊⍴)⍵:¯1 ⍝ Axiom 5: nothing before something
  25. ⍺<Ö(0∊⍴)⍵:1 ⍝ something after nothing
  26.  
  27. ⍺≢Ö(⍴⍴)⍵:c+(⍺ ∇ Ö(⍴⍴)⍵)×0=c←⍺ ∇ Ö(⊢⍴⍨⍴,⍨1⍴⍨r-(⍴⍴))⍵⊣r←⍺⌈Ö(⍴⍴)⍵ ⍝ Axiom 6: extend rank, compare, tie-break by rank
  28.  
  29. ⍺≢Ö⍴⍵:c+(⍺ ∇ Ö(⌽⍴)⍵)×0=c←(⍺ ∇ Ö(m∘↑)⍵)⊣m←⍺⌊Ö⍴⍵ ⍝ Axiom 5: chop shape, compare, tie-break by shape
  30.  
  31. t←⍺,Ö{(326≠t)×2-2|t←⎕DR ⍵}⍵ ⍝ Axiom 4: 1=num; 2=char; 0=other
  32. 1 2≡t:¯1 ⍝ num vs char
  33. 2 1≡t:1 ⍝ char vs num
  34.  
  35. 1 1≡t:⊃0~⍨,⍺(>-<)Ö(9 11∘○⍤1 0)⍵ ⍝ Axioms 3 & 2: first nonzero value of num vs num with catenated Zs
  36. 2 2≡t:⊃0~⍨,⍺(>-<)Ö ⎕UCS ⍵ ⍝ Axioms 1 & 2: first nonzero value of char vs char using ⎕UCS
  37.  
  38. |c←⍺ ∇ Ö⊃⍵:c ⋄ ⍺ ∇ Ö(1↓,)⍵ ⍝ Axiom 2: first non-zero in ravel order (for non-simple arrays)
  39. }
Add Comment
Please, Sign In to add comment