Functions

Identifiers

An identifier (name of function, variable, type, or any other thing) can contain letters, numbers, _ and -.
It can't begin with a number, or begin or end with -.
Many character sets are supported; file an issue if yours isn't.
Examples: a, is-empty, float32, BIG_WORDS, עורב, 까마귀.

The standard library uses kebab-case, which means lower-case words separated by hyphens.

Function names can also be operators like +. Those will be described in Special call syntax.

Function call syntax

In Crow, a function name always comes after its first argument (if any).
The first column below shows how to call a function f in Crow.
The other columns show an equivalent in other languages.

f() f(a) f(a, b) f(a, b, c)

You can edit any cell above to experiment. This does not use a full parser; it only supports identifiers and calls.

f in Crow could be either f or f() in C. It accesses a variable if one is in scope; otherwise, it is a function call.

You can write a.f to avoid needing to parenthesize (a f). This only works for a function with one argument.

abs(sin(a)) in(id(a), allowed(b))

Without a ., function names bind loosely.
When you see a function name, everything to the left of it is the first argument.

then(then(a, b), c) in(a, allowed(b, purpose)) draw(triangle(a, b, c))

If the function name is prefixed with ! or suffixed with !, not or force (respectiely) are called after the function.

not(in(x, xs)) force(parse(nat, str))

Function definition syntax

Now we're ready to define a function and call it:

main void() info log hello-world hello-world string() "Hello, world!"

info log hello-world calls the function log with 2 arguments info and hello-world, which are 0-argument function calls.

hello-world string() is the function signature. It takes no arguments and returns a string. The function body always goes beneath the signature and indented.

Parameters

Here's a modified version that takes a single parameter.

main void() info log 3.hello-world hello-world string(times nat) "Hello, world! " repeat times

This defines a function hello-world that takes a nat (natural number) and returns a string.
The argument 3 becomes the value of the parameter times, causing the string to repeat 3 times.

The below takes 2 parameters name and times and passes arguments "crow" and 3, respectively.

main void() info log ("crow" hello 3) hello string(name string, times nat) "Hello, {name}! " repeat times

"Hello, {name}! " is string interpolation. This will be explained in Basic types.