Examples
Copyable examples for every version of epher. Paste them into a terminal, a REPL session, or the app's entry field. The user guide explains the language in detail; this page is for quick copying and pasting.
On a phone, tap an example to open the app with it ready to run.
TUI, desktop app, and web app
The same language runs in the terminal UI, the desktop app, and the web app. Copy/paste an example into the entry field and press Enter.
2 + 3 * 4
sqrt(2 ^ 10)
frac(1, 3) + frac(1, 6)
def sq(x) = x * x; sq(9)
def hyp(a, b) do
c = a ^ 2 + b ^ 2
sqrt(c)
end
hyp(3, 4)
def firstsq(xs) do
for x in xs do
if x ^ 0.5 == floor(x ^ 0.5) then return x
0
end
firstsq({3, 5, 9, 11})
{name, ext} = split("report.txt", ".")
join({upper(name), ext}, ".")
0xff + 0b1
hex(ans)
x = 10
y = x + 5
y ^ 2
graph x ^ 2
graph y < x ^ 2
const a = 1
graph sin(x * a)
graph x ^ 2
graph sin(x)
graph3d sin(x) * cos(y)
graph3d x ^ 2 + y ^ 2
kepler(5, 0.1)
def planck(x) = (2 * h * c ^ 2) / ((x * 1e-9) ^ 5 * (exp((h * c) / ((x * 1e-9) * k_b * 5778)) - 1))
graph planck(x) from 100 to 2000
const t = now()
solar3d t
def flux(x) = 1 - 0.012 / (1 + exp((abs(x) - 0.04) * 200))
graph flux(x) from -0.2 to 0.2
The command line
One-shot calculations, piped scripts, and SVG exports. Copy an example from those below into any shell.
printf 'x = 10\nx ^ 2\n' | epher -
epher "1 / 3" | tee third.txt
epher "x = 7; x ^ 3"
printf 'def fact(n) = if n <= 1 then 1 else n * fact(n - 1); fact(10)' | epher -
epher "graph x ^ 2; graph save plot.svg"
epher "graph3d x ^ 2 - y ^ 2; graph3d save saddle.svg"
The REPL
Start an interactive session with `epher repl` and type after the `epher>` prompt. These blocks run one after another in the same session. Each answer feeds the next line's `ans`.
epher> 2 + 3
= 5
epher> ans * 10
= 50
epher> ans + 2
= 52
epher> (ans - 12) ^ 2
= 1600