language

Operators

Akkado uses operators for arithmetic, signal flow, and more.

Akkado uses operators for arithmetic, signal flow, and more.

Operator Precedence

From highest to lowest precedence:

OperatorNameExample
.Method callsig.map(f)
^Powerx ^ 2
* /Multiply, Dividea * b
+ -Add, Subtracta + b
\|>Pipea \|> b

Arithmetic Operators

All arithmetic operators work on signals at audio rate:

// Addition - mix two oscillators
osc("sin", 220) + osc("sin", 330) |> out(%, %)

// Subtraction - phase cancellation
osc("sin", 220) - osc("sin", 220.5) |> out(%, %)

// Multiplication - amplitude modulation
osc("sin", 220) * osc("sin", 5) |> out(%, %)

// Division - scaling
osc("saw", 110) / 2 |> out(%, %)

// Power - exponential curves
lfo(0.5) ^ 2 |> out(%, %)

Operator Desugaring

Operators are converted to function calls:

OperatorDesugars To
a + badd(a, b)
a - bsub(a, b)
a * bmul(a, b)
a / bdiv(a, b)
a ^ bpow(a, b)

The Pipe Operator

The |> operator defines signal flow. It has the lowest precedence:

// Signal flows left to right
osc("saw", 110) |> lp(%, 800) |> out(%, %)

See Pipes & Holes for full details.

The Hole Operator

The % symbol is an explicit input port:

// % refers to the left-hand side of |>
osc("saw", 110) |> lp(%, 500) |> out(%, %)

Combining Operators

Operators follow precedence rules:

// Multiplication before addition
a + b * c    // equals a + (b * c)

// Use parentheses to override
(a + b) * c  // equals (a + b) * c

// Pipe has lowest precedence
a + b |> lp(%, 500)  // equals (a + b) |> lp(%, 500)

Unary Minus

Negation works on numbers and signals:

// Negative number
saw(-110)   // Won't work - use neg()

// Correct way
osc("saw", 110) |> neg(%) |> out(%, %)

// Or multiply by -1
osc("saw", 110) * -1 |> out(%, %)

Related: Pipes & Holes, Math Functions