Anatomy of a Function
The following are all the predicates that you can specify when creating a function.
Predicate | Type | Description |
---|---|---|
name | string | Function name |
params | (multi) string | List of parameters this function supports. |
code | string | Actual ledger code |
doc | string | A docstring for this function. |
language | string | Programming language used (not yet implemented, currently only Clojure supported) |
spec | JSON | (not yet implemented) Optional spec for parameters. Spec should be structured as a map, parameter names are keys and the respective spec is the value. |
In the next lesson, we'll be talking a lot more about _fn/code
, but for now take a look at an example function, which subtracts 3 from a value:
[
{
"_id": "_fn",
"name": "minus3",
"params": ["a"],
"code": "(- a 3)",
"doc": "Subtracts 3 from a value, a"
}
]
As you can see above, our code takes a parameter, a
. We declare a
in _fn/params
, and we can therefore use it in our code.