Examples

Polonio 1.0 includes small examples designed to demonstrate one concept at a time. See the examples guide for commands and setup.

Language examples

Hello

hello.pol demonstrates a `.pol` program, variables, expressions, and output.

<% var name = "Polonio" %>
<h1>Hello, $name</h1>

Fibonacci

fibonacci.pol demonstrates functions, parameters, return, recursion, and numeric comparisons.

function fibonacci(n)
  if n <= 1 return n end
  return fibonacci(n - 1) + fibonacci(n - 2)
end

Closures

closures.pol demonstrates lexical capture, mutable captured bindings, and persistent closure state; it follows Polonio's lexical-scope semantics.

Collections and Aliasing

collections_aliasing.pol shows arrays as reference-like mutable collections, mutation through aliases, rebinding, and structural equality.

var alias = original
push(alias, 3)
echo original == [1, 2, 3]

Conway's Game of Life

game_of_life.pol is the larger language example: nested arrays, functions, loops, comparisons, mutation, continuous execution, and CLI streaming.

./build/polonio run examples/game_of_life.pol

Stop it with Ctrl-C; do not paste the program into a terminal.

Web/runtime examples

Templates

hello.pol combines literal HTML, code blocks, variable output, loops, and explicit HTML escaping where needed.

Session Counter

session.pol uses signed sessions, session_get, session_set, and request persistence. Set POLONIO_SESSION_SECRET.

SQLite Guestbook

guestbook.pol is a runtime example, not a framework architecture recommendation:

GET → form → POST → CSRF → SQLite → redirect → escaped rendering

Set POLONIO_STORAGE_PATH and POLONIO_SESSION_SECRET, then run:

./build/polonio serve --root ./examples --port 8080