Sharpening your APL knife

Assumptions

Assumptions -1-

  • ∇ r←DropRubbish string
  • [1]  r←¯4↓string∇

Assumptions -2-

  • ∇ r←DropRubbish string
  • [1]  r←¯4↓string ∇

The better way

  • ∇ r←DropExtension fullPathName
  • [1]  r←¯4↓fullPathName ∇

Even better!

  • ∇ r←DropExtension fullPathName
  • [1]  r←{⍵↓⍨-'.'⍳⍨⌽⍵}fullPathName ∇

Almost perfect

  • ∇ r←DropExtension fullPathName
  • [1]  r←{'.'∊⍵:⍵↓⍨-'.'⍳⍨⌽⍵ ⋄ ⍵}fullPathName ∇

Make it shout

  • ∇ r←DropExtension fullPathName;errMsg
  • [1] errMsg←'Invalid extension'
  • [2] errMsg ⎕signal 11/⍨'.'≠1⊃¯4↑fullPathName
  • [3]  r←¯4↓fullPathName∇

Types of assumptions

There are all kinds of assumptions in our way:

Size -1-

  • 2⊃⎕vfi¨↓matrix
  •  

Size -2-

  • The matrix turns out to have up to 100.000 rows
  • 2⊃∘⎕vfi¨↓matrix
  • takes on my machine 190 ms
  • 2⊃⎕vfi,' ',↑,matrix
  • would have taken less then 50% of that instead

Assumptions in strategies -1-

Assumptions in strategies -2-

Note that the workspace size was restricted to 4 MB then

The files contained 0 to some 10.000 records

That's what I found:


Assumptions in strategies -3-

Obviously that could be improved a lot:

Problem is: restrictions can be lifted

Assumptions in strategies -4-

End