Skip to main content

Universal Functions - Part 2

After we've added a function to our ledger, we can use our custom function in additional functions. For example, take minus3, below:

[  {    "_id": "_fn",    "name": "minus3",    "params": ["a"],    "code": "(- a 3)",    "doc": "Subtracts 3 from a value, a"  }]

We can create a new function that takes the max of 10, 55, and the result of applying minus3 to a value.

[  {    "_id": "_fn",    "name": "maxValsAndMinus3",    "params": ["b"],    "code": "(max 10 55 (minus3 b))",    "doc": "Takes the max of 10, 55, and (minus3 b)."  }]
// Note, we can hardcode a number into minus3, (minus3 20), or we can use a parameter (as we do above).

Function List#

For convenience, we've linked the full list of all available universal functions again.

Function code examples:

(+ 12 5)                                   ;; 17(inc 10)                                   ;; 11(== 1 1)                                   ;; true(+ 12 (max 1 2 3))                 ;; 15(if-else (== 1 1) "a" "b")      ;; "a"