Remarks:
*
is exponentiation. Multiplication is ×
IO
)https://aplwiki.com/wiki/Reshape
Two forms:
Dyadic examples:
> 2 4 ρ ⍳ 8
1 2 3 4
5 6 7 8
> 3 2 ρ ⍳ 6
1 2
3 4
5 6
> ⍝ Looks like truncation happens if shape doesn't fit
> 3 2 ρ ⍳ 8
1 2
3 4
5 6
Monadic example:
> ρ 2 4 ρ ⍳ 8
2 4
https://aplwiki.com/wiki/Index_Generator
> ⍳ 9
1 2 3 4 5 6 7 8 9
> ⍝ Set index origin so that ⍳ starts from 0
> ⎕IO ← 0
> ⍳ 9
0 1 2 3 4 5 6 7 8
> ⊖ ⍳ 5
5 4 3 2 1
> ⍝ Rows got reversed
> ⊖ 3 2 ρ ⍳ 6
5 6
3 4
1 2
> ⌽ 3 2 ρ ⍳ 6
2 1
4 3
6 5
> 3 2 ρ ⍳ 6
1 2
3 4
5 6
> ⍝ Columns got reversed
> ⌽ 3 3 ρ ⍳ 9
3 2 1
6 5 4
9 8 7
> ⍝ Columns got reversed
> ⍉ 2 3 ρ ⍳ 6
1 4
2 5
3 6
Drop first n elements of an array.
> 1 ↓ 1 2 3 4 5 6 7
2 3 4 5 6 7
> 2 ↓ 1 2 3 4 5 6 7
3 4 5 6 7
Take first n elements of an array.
> 2 ↑ 1 2 3 4 5 6 7
1 2
> 4 ↑ 1 2 3 4 5 6 7
1 2 3 4
> 2 / 3 4 5
3 3 4 4 5 5
> 1 / 3 4 5
3 4 5
> 3 / 3 4 5
3 3 3 4 4 4 5 5 5
> 2 / (3 4 5) (6 7)
3 4 5 3 4 5 6 7 6 7
> 2 4 ρ ι 8
1 2 3 4
5 6 7 8
> + ⌿ 2 4 ρ ι 8
6 8 10 12
First axis here is column-wise ??
> 2 4 ρ ι 8
1 2 3 4
5 6 7 8
> + / 2 4 ρ ι 8
10 26
> 2 4 ρ ι 8
1 2 3 4
5 6 7 8
> + \ 2 4 ρ ι 8
1 3 6 10
5 11 18 26
> + ⍀ 2 4 ρ ι 8
1 2 3 4
6 8 10 12
> !5
120
—
For an array, it's a map to all elements:
> 2 4 ρ ι 8
1 2 3 4
5 6 7 8
> ! 2 4 ρ ι 8
1 2 6 24
120 720 5040 40320
Nesting depth.
> ≡ 2 4 ρ ι 8
1
> ≡ ι 8
1
? n
selects a number randomly from the first n numbers.
> ? 100
97
> ? 100
76
> ? 100
82
> ? 100
92
n must be greater than 0.
> ? 0
DOMAIN ERROR
?0
^
Both are monadic.
> ⌈ 3.2
4
> ⌈ 3.5
4
> ⌈ 3
3
> ⌊ 3
3
> ⌊ 3.5
3
> ⌊ 2.9
2
> ⍳ 8
1 2 3 4 5 6 7 8
> 2 * ⍳ 8
2 4 8 16 32 64 128 256
Not yet sure how this came about though:
> * ⍳ 8
2.718281828 7.389056099 20.08553692 54.59815003 148.4131591 403.4287935
1096.633158 2980.957987
> n ← 5 6 7
> n + 2
7 8 9
> +/n
18
> -/n
> ⍝ 5 - (6 - 7)
6
> ×/n
210
> */n
> ⍝ Because * is exponentiation
> ⍝ 5^(6^7) is quite a large number (a 195667-digit number)
∞
emacs: gnu-apl mode
M-x gnu-apl-mode
Default keyboard is like (from here):
╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦═════════╗
║ ~ ║ !⌶ ║ @⍫ ║ #⍒ ║ $⍋ ║ %⌽ ║ ^⍉ ║ &⊖ ║ *⍟ ║ (⍱ ║ )⍲ ║ _! ║ +⌹ ║ ║
║ `◊ ║ 1¨ ║ 2¯ ║ 3< ║ 4≤ ║ 5= ║ 6≥ ║ 7> ║ 8≠ ║ 9∨ ║ 0∧ ║ -× ║ =÷ ║ BACKSP ║
╠════╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦══════╣
║ ║ Q ║ W⍹ ║ E⋸ ║ R ║ T⍨ ║ Y¥ ║ U ║ I⍸ ║ O⍥ ║ P⍣ ║ {⍞ ║ }⍬ ║ |⊣ ║
║ TAB ║ q? ║ w⍵ ║ e∈ ║ r⍴ ║ t∼ ║ y↑ ║ u↓ ║ i⍳ ║ o○ ║ p⋆ ║ [← ║ ]→ ║ \⊢ ║
╠═══════╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩══════╣
║ (CAPS ║ A⍶ ║ S ║ D ║ F ║ G ║ H⍙ ║ J⍤ ║ K ║ L⌷ ║ :≡ ║ "≢ ║ ║
║ LOCK) ║ a⍺ ║ s⌈ ║ d⌊ ║ f_ ║ g∇ ║ h∆ ║ j∘ ║ k' ║ l⎕ ║ ;⍎ ║ '⍕ ║ RETURN ║
╠═════════╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═════════╣
║ ║ Z ║ Xχ ║ C¢ ║ V ║ B£ ║ N ║ M ║ <⍪ ║ >⍙ ║ ?⍠ ║ ║
║ SHIFT ║ z⊂ ║ x⊃ ║ c∩ ║ v∪ ║ b⊥ ║ n⊤ ║ m| ║ ,⍝ ║ .⍀ ║ /⌿ ║ SHIFT ║
╚═════════════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩══════════╝
(Depending on the font used, this may look different on different devices.)
vim-apl: https://github.com/zoomlogo/vim-apl
Backtick is the prefix key by default:
`i
gives ι
`$
gives ⍋
`r
gives ρ
REPL:
)OFF