Studio

Fun With Functions

What you type in an APL session is indented with six spaces.

      ⎕←'Hello World!'
Hello World!

      ⍳5
1 2 3 4 5

      20+⍳5
21 22 23 24 25

      2 3 4 + 100 500 200
102 503 204

      2 3 4 × 100 500 200
200 1500 800

      (⍳3)∘.+⍳3 ⍝ addition table
2 3 4
3 4 5
4 5 6

      (⍳3)∘.×⍳3 ⍝ multiplication table
1 2 3
2 4 6
3 6 9

      ∘.×⍨⍳3 ⍝ reflex operator (Dyalog) uses right argument on left
1 2 3
2 4 6
3 6 9

      ∘.=⍨⍳3 ⍝ identity matrix
1 0 0
0 1 0
0 0 1

      im←∘.=⍨∘⍳ ⍝ define a function (Dyalog)

      im 5 ⍝ use it
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

Studio/FunWithFunctions (last edited 2008-08-20 18:57:19 by anonymous)