This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Functions

def, return, docstrings, recursion, and optional type annotations. Run a cell to see its output beside the expected one.

def and return

Viv [1]

Docstrings

A bare string as the first statement documents the function and compiles to nothing.

Viv [2]

Recursion

A double holds every integer up to 2^53 exactly, so a counter can stop the recursion with equality; a comparison such as n < 1.5 also stops it when n is not a whole number.

Viv [3]

Type annotations

Optional; the compiler checks them before the program runs.

Viv [4]

A def with no return gives nothing

A def that ends without a return is called as a statement. Its value is nothing: the compiler refuses show f(x) or f(x) + 1.0 for it.

Viv [5]

Early return

Viv [6]

Call before definition

Top-level defs are collected before anything runs, so source order does not matter.

Viv [7]

Lambdas pass as arguments

A def can take a function value and call it.

Viv [8]

Parameters shadow globals

Viv [9]

Several results

return a, b gives two values, and the caller unpacks them on a line of its own; a, b = b, a swaps.

Viv [10]