Snapshot.jl
← Notebooks/Wasm Islands: Success & Failure🏝️ 1/2 cells interactive
.jl source
import AbstractPlutoDingetjes.Bonds

Wasm islands: a success and a deliberate failure

Snapshot compiles the cells behind each @bind to WebAssembly so the export stays interactive without a server. This notebook shows both outcomes on purpose:

  • the first slider's cells are type-stable Julia β†’ they ship as a live wasm island;

  • the second slider's cells contain a deliberately type-unstable helper β†’ the compile is refused loudly, and the export shows a diagnostic card explaining exactly which construct failed, in which cell, and why.

βœ… The success: a typed Collatz walk

Everything below is concretely typed (Int64 in, Int64 out) β€” exactly the strict subset WasmTarget compiles. Drag the slider: the step count updates live, in-browser.

@bind n RangeSlider(500)
collatz_steps (generic function with 1 method)
function collatz_steps(m::Int64)::Int64
	steps = Int64(0)
	x = m
	while x != 1
		x = iseven(x) ? x Γ· 2 : 3x + 1
		steps += 1
	end
	steps
end

1 reaches 1 in 0 Collatz steps.

⚑ The deliberate failure: an Any grab-bag

The helper below stuffs a slider value, a float, and a string into an Any[] container and folds over it β€” classic type instability. Native Julia shrugs; WasmTarget refuses to guess and reports the exact unsupported construct. The output cell that depends on it gets the diagnostic card in the export β€” note it points back at the helper cell, not just the broken output.

@bind k RangeSlider(100)
grab_bag_total (generic function with 1 method)
function grab_bag_total(j::Int64)
	items = Any[j, 2.5, "three"]
	total = 0
	for it in items
		total += it isa String ? length(it) : it
	end
	total
end

the grab-bag total for 1 is 8.5

Pluto notebooks as lean Therapy components β€” interactive WebAssembly, no server.