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.
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.
Without a ., function names bind loosely.
When you see a function name, everything to the left of it is the first argument.
If the function name is prefixed with ! or suffixed with !,
not or force (respectiely) are called after the function.
Function definition syntax
Now we're ready to define a function and call it:
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.
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.
"Hello, {name}! " is string interpolation.
This will be explained in Basic types.