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:
- Assigning functions situated not in the current namespace but elsewhere
- Causes all sorts of trouble
Search Functions -1-
List of all search functions:
⍳ ∊ ∩ ∪ ~ and "matrix iota" (idiom)
- For best performance, hash tables are used by search functions
- Building up a hash table takes quite some time
- Pays off when the search is performed
- Drawback in case of an "eached" or otherwise repeated search function
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
- There is no equivalent for NULL (no value) in APL
- Especially empty strings cannot represent NULL
- NULL does not stand for any data, it stands for the absence of data.
- ⎕NULL makes it possible to check data for being or containing NULL
End