The Crow Programming Language

Defining and Calling Functions

fn, a name, parameters in square brackets, an indented body:

1
2
3
4
fn area[w, h]
    return w * h

log[area[3, 4]]

expected output — from the book, verified by crow test --book

12

The last expression in a body is the return value, so return on the final line is optional:

1
2
3
4
fn cube[x]
    x * x * x

log[cube[3]]

expected output — from the book, verified by crow test --book

27

Functions Are Values

A function name without brackets is the function — store it, pass it, call it later. This is how Crow does everything other languages use lambdas for (Crow has no lambdas — a deliberate choice; named functions keep every callsite greppable and every behavior testable):

1
2
3
4
5
6
7
8
9
10
fn cube[x]
    x * x * x

op = cube
log[op[2]]

fn apply_twice[f, x]
    return f[f[x]]

log[apply_twice[cube, 2]]

expected output — from the book, verified by crow test --book

8
512