Functions
Documentation/specification of Jingle's syntax
Functions
Function types
Overview
Just like any other modern programming language, Jingle contains functions. Jingle's functions are first-class, similar to other languages which means that it can be passed as an argument. Functions in Jingle are also treated as objects like everything else.
Functions are defined with the following syntax:
Invoking functions
Now that we know how to define functions, we need to be able to invoke it. Functions can be called from the scope that they are defined in. For example:
Function parameters
In some cases functions may not need parameters but most of the time, functions are useless unless you can pass values to them. So far, every function shown does not accept or require parameters. If your function requires parameters, you add them in a parentheses-delimited list between the function's name and start of the function body (:).
There is theoretically no limit on the amount of parameters a function can have, shown here in a function with 6 parameters:
Returning values
The body of a function is a block. If the block is a single expression then the implicit returned value of the function is that of the single expression. Otherwise, the block will return nil
by default. Explicit returning of values is defined using a return
statement. For example, these 2 functions both do the same thing:
Function types
Functions can be given a type using the arrow ->
operator.
The type of a function dictates what it expects to be returned.
Closures?
Closures in Jingle are still being designed.
Block arguments?
Block arguments in Jingle are still being designed.
Last updated