Your First Session¶
This page walks you through a first interactive session with MARPLE. Launch the REPL (marple) and follow along.
MARPLE as a calculator¶
APL works right to left, like mathematics. Try some arithmetic:
Note
APL uses × for multiplication and ÷ for division, not * and /. The * symbol means power (exponentiation), and / means reduce.
Right-to-left evaluation means there's no precedence — every function takes everything to its right as its argument:
This is 2 × (3 + 4), not (2 × 3) + 4. There's no precedence to memorise: just read right to left.
Vectors¶
Type several numbers separated by spaces to create a vector:
Arithmetic works element-wise on vectors:
When one argument is a scalar and the other is a vector, the scalar is paired with every element. This is called scalar extension:
Generating arrays with Iota¶
The ⍳ function (iota) generates a sequence of integers:
Reduce¶
The / operator inserts a function between every element of a vector. +/ sums a vector:
×/ computes a product — so ×/⍳5 gives you 5 factorial.
Matrices¶
Use ⍴ (rho) to reshape a vector into a matrix. The left argument is the shape:
This creates a 3-row, 4-column matrix filled with the numbers 1 to 12.
You can ask for an array's shape with monadic ⍴:
Assigning names¶
The ← arrow assigns a value to a name:
Names are case-sensitive. M, m, and Matrix are three different names.
Defining functions¶
Curly braces {} define a dfn (direct function). Inside, ⍵ is the right argument and ⍺ is the optional left argument:
A dyadic dfn:
Saving your work¶
Give your workspace a name and save it:
Next time, load it back:
What next?¶
- New to APL? Continue with the beginner tutorials, starting with Arrays
- Know APL already? See MARPLE for Dyalog Users or jump to the Reference
- Want to see worked examples? Try the Worked Examples section