f00 in 5 minutes
Loading the f00 runtime…
f00 is a small Rebol-family scripting language, running here as WebAssembly in your browser. Every example below is editable: change it and press Run. Each Run starts a fresh f00 VM, so nothing carries over from one example to the next, and the result after => is the value of the last expression. A line starting ** is an error.
This page is instructional and its examples are tested against the real runtime; where the page and the language differ, the language wins. Prefer a prompt? Use the f00 REPL.
1. Values and words
A program is a sequence of values. A word names a value, and a set-word (a word with a colon after it) gives it one. Arithmetic runs left to right with no operator precedence: 1 + 2 * 3 is (1 + 2) * 3. Dividing two integers truncates.
=> 8
=> 9
=> 3
=> 3.5
A word with a leading quote is a word used as data, not looked up.
=> tea
type? tells you what a value is. print shows a value as a line of output; the last expression is the result, shown after =>.
integer! string! => decimal!
2. Blocks are data
Square brackets make a block: a list of values that is just data until something evaluates it. do evaluates a block. A block result is shown as [block], not as its contents; use print to see the elements.
=> [block]
=> 3
10 20 30 => none
3. Functions
func [params] [body] makes a function. A call needs no parentheses or commas: the function takes as many following values as it has parameters, so calls nest by arity: double double 5 is double (double 5).
=> 42
=> 12
=> 20
rejoin joins the values of a block into one string.
=> Hello, world!
A function can call itself.
=> 3628800
Arity is fixed. Too few arguments is an error, and an extra one is not an argument at all:
** f00 eval missing value
Here add 1 2 ran, and the 3 started the next statement, so the last value is 3.
=> 3
4. Deciding
A test is a comparison such as x > 5. either runs one of two blocks; if runs a block or gives none. Both are values, so you can bind the result.
=> big
=> none
=> b
true true => false
5. Repeating
repeat i n counts from 1 to n. while repeats while a block is true, foreach walks a block, and loop repeats a fixed number of times. break leaves a loop and continue skips to the next turn.
=> 15
=> 3
=> 60
hi hi hi => none
=> 6
=> 18
6. Series
Blocks and strings are series. pick reads by position (from 1) and length? counts. insert, remove and poke change a block in place; next and skip give a view further along it, and head takes you back to the start. Only blocks can be appended to: append on a string is an error.
20 => 3
99 20 30 => 3
20 => 1
c is a view starting at the third element; head c is the whole block again.
30 10 => 3
h => 5
=> n=42
7. Objects and paths
make object! builds a bundle of named values. A path reaches into it, and can assign: p/age: 31.
Ann => 31
=> 7
8. Scope and closures
A function sees its own parameters and the globals, and a parameter shadows a global of the same name. A function can build and return another function, which keeps the parameters it captured. One trap: a set-word inside a function body sets a global, it does not make a local.
2 => 10
=> 15
Each counter keeps its own n: the parameter it captured. c ran twice and d once, and they did not disturb each other.
=> 101
The y: inside f is not local: after f runs, y is bound to 3 everywhere.
=> 3
9. When things go wrong
A failed line says why. When a function was running, it also says where: the trace lists the word that failed and the calls it was inside, innermost first, with each call's parameters. The last example never ends; Run it and it stops itself after five seconds.
** f00 eval unbound word word: oops
** f00 eval wrong type
** f00 eval invalid input
f called g, which failed on nosuch.
** f00 eval unbound word word: nosuch in g [b: 2] in f [a: 1]
Not yet
f00 is small. These words look like they should exist but are not defined yet: first, find, select, reverse, max, abs, not, and, all, any, switch, case, mold, form. There are no parentheses either. Running find shows what that looks like:
** f00 eval unbound word word: find
Want a prompt instead of a page? Try the f00 REPL, or read how f00 is embedded in a Recoil program.