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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

A word with a leading quote is a word used as data, not looked up.

Ctrl+Enter runs

                
            

type? tells you what a value is. print shows a value as a line of output; the last expression is the result, shown after =>.

Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

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).

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

rejoin joins the values of a block into one string.

Ctrl+Enter runs

                
            

A function can call itself.

Ctrl+Enter runs

                
            

Arity is fixed. Too few arguments is an error, and an extra one is not an argument at all:

Ctrl+Enter runs

                
            

Here add 1 2 ran, and the 3 started the next statement, so the last value is 3.

Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

c is a view starting at the third element; head c is the whole block again.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

7. Objects and paths

make object! builds a bundle of named values. A path reaches into it, and can assign: p/age: 31.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

Each counter keeps its own n: the parameter it captured. c ran twice and d once, and they did not disturb each other.

Ctrl+Enter runs

                
            

The y: inside f is not local: after f runs, y is bound to 3 everywhere.

Ctrl+Enter runs

                
            

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.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            
Ctrl+Enter runs

                
            

f called g, which failed on nosuch.

Ctrl+Enter runs

                
            
Ctrl+Enter runs

            

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:

Ctrl+Enter runs

                
            

Want a prompt instead of a page? Try the f00 REPL, or read how f00 is embedded in a Recoil program.

↑