Runnable Viv on a plain HTML page
This page is intentionally boring: no framework, no bundler, no server. It loads
viv-embed.js with one script tag, and every <viv-cell>
below is a live, editable Viv program running on the wasm compiler in your browser.
Edit and run
narrate "computing"
def sq(x) {
return x * x
}
total = 0.0
for i to 10 {
total += sq(i)
}
show total
Plots work
n = 61
t = linspace(0.0, 6.0, n)
y = zeros(n)
for i to n {
y[i] = exp(-0.5 * t[i]) * cos(3.0 * t[i])
}
figure("A damped cosine", "t", "y")
plot(t, y, "damped cosine")
And the call graph
Run this, then expand the call-graph line under the output.
def leaf(x) { return x + 1.0 }
def branch(x) { return leaf(x) + leaf(x) }
def trunk(x) { return branch(x) }
s = 0.0
for i to 4 {
s += trunk(i)
}
show s
Markdown-rendered sites work too: any <pre><code class="language-viv">
block is upgraded automatically.