Sharpening your APL knife

Misc

Function assignment -1-

  •   Plus←+ ⋄ Minus←- ⋄ And←∧ ⋄ Not←~ ⋄ Or←∨
  • ⍝ Valueable for developing a domain specific "language"
  •   3 Plus 5
  • 8
  •   Sum←+/
  •   Sum ⍳3
  • 6

Function assignment -2-

  •   Mix←↓∘⍉∘↑
  •   Mix ('Name' 'George')('Surname' 'Bush')
  • Name  Surname    George  Bush
  • ⍝ Might be considerably faster than other approaches
  •   Mix¨LongVectorOfLargeArrays

Function assignment -3-

Things to be avoided:

Search Functions -1-

List of all search functions:

⍳ ∊ ∩ ∪ ~ and "matrix iota" (idiom)

Search Functions -2-

"Composition" operator to the rescue!

  •   list←400000⍴'This' 'And' 'That' 'x' 'yy'
  •   z←list∊¨⊂⎕a
  • ⍝ Takes 1.496 seconds
  •   z←∊∘⎕a¨list
  • ⍝ Takes 0.56 seconds
  • ⍝ The hash table is build up only once and then re-used

Search Functions -3-

"Function Assignment" to the rescue!

  •   list←⍕¨?400000⍴400000
  •   searched←list[100?⍴list]
  •   list⍳searched
  • ⍝ Takes 2.67 seconds
  •   find←list∘⍳
  •   find searched
  • ⍝ Takes 1.234 seconds

[]THIS

Returns a ref to the namspace/class/instance it is executed in.

The same could be achieved with:

  • ⍎''⎕ns''
  • Therefore:
  • ⎕this ←→ ⍎''⎕ns''

Note that ⎕NS works only with namespaces, while ⎕THIS works also with instances and classes

[]NULL

End