Naming Conventions |
|||||
|
Scalar |
Vector |
Matrix |
Any |
Non- |
Boolean |
BS |
BV |
BM |
BA |
BN |
Integer |
IS |
IV |
IM |
IA |
IN |
Float |
FS |
FV |
FM |
FA |
FN |
Numeric |
NS |
NV |
NM |
NA |
NN |
Character |
CS |
CV |
CM |
CA |
CN |
Enclosed |
ES |
EV |
EM |
EA |
EN |
enclosed |
TS |
TV |
TM |
TA |
TN |
Simple |
SS |
SV |
SM |
SA |
SN |
Any |
AS |
AV |
AM |
AA |
AN |
phrase e.g.: .X...Y. ⍝ X←BS; Y←IV |
|||||
combinations: use ISV for Integer scalar∨vector |
|||||
B3, I4 &c. to specify higher ranks. |
|||||
Boolean To Index
IV←BV/⍳⍴BV
Below are the six top significant entries, excluding decorators in comments, in a frequency table of triplets of contiguous APL primitives occurring in a 5 3/4 million character workspace.
/⍳⍴ 223 ⊃,/ 195 ∧.≠ 195 =↑⍴ 169 +/∧ 139 /∧\ 136
This is about the very first of them: /⍳⍴ that returns the index positions of the 1s in a boolean vector.
Its ubiquity ensures that nearly everyone reading this will have seen it countless times. For a beginner it might not be so immediately obvious. Its equivalence to a monadic function, having only one array to deal with, is often hidden by coders' reluctance to assign temporary values within a line of code:
(bf AV)/⍳⍴AV ⍝ where bf is some boolean-returning scalar function
z/⍳⍴z←bf AVSome coders go so far as to define a named function and use that wherever the phrase would be used otherwise. At least one interpreter had it implemented as a primitive.
Examples
⎕FX⍕2 1⍴'IV←B2I BV' 'IV←BV/⍳⍴,BV'
Display B2I'BooleanToIndex'∊'aeiou'
┌→───────────┐
│1 2 4 5 8 12│
└~───────────┘
Display B2I'aeiou'∊'BooleanToIndex'
┌→────┐
│0 1 3│
└~────┘Note the comma which is needed to make sure that the right argument is a vector. Without the comma things get nasty:
⍝ Dyalog prior to Version 13.0:
z/⍳⍴z←1
1
⍝ Dyalog Version 13.0 and later:
z/⍳⍴z←1
(,⊂⍬)≡z/⍳⍴z←1
1
⍝ NARS2000
(,⊂⍬)≡z/⍳⍴z←1
1
⍝ APLX
z/⍳⍴z←1
RANK ERROR
Specialities
As mentioned above it has been implemented as a primitive (⍵).
Can anyone remember where?
Dyalog
The triglyph is recognised by the Dyalog interpreter as an idiom and highlighted as such by syntax colouring.
Dyalog also allows one to code it simply as an unnamed monadic dfn {⍵/⍳⍴⍵} using parameter substitution instead of assignment of BV.
Compatibility
Checked with: APL2, APLX, Dyalog, NARS2000
Test Cases
Show test cases
Test my code, both Examples and Test Cases.
See also: ...
Mentor: PhilLast
Tags: <AppropriateCamelCaseName> <Simpleword>
APL Wiki