Functions are central in Crystal. We’ll learn about functions with a few different examples.
To run the program, save it as functions.cr and use the crystal command:
There are several other features to Crystal functions. One is multiple return values, which we’ll look at next.
Note: Crystal’s syntax is very similar to Ruby, but it adds static type checking. Unlike Go, Crystal doesn’t require explicit type annotations in many cases due to its powerful type inference system. However, we’ve included type annotations in this example for clarity.