diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index 5d34a5e74..f8fc729a6 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -299,6 +299,41 @@ gitlab-pages/docs/language-basics/src/functions/incr_map.religo incr_map + +## Nested functions (also known as closures) +It's possible to place functions inside other functions. These functions +have access to variables in the same scope. + + + +```pascaligo +function closure_example (const i : int) : int is + block { + function closure (const j : int) : int is i + j + } with closure (i) +``` + + + + +```cameligo +let closure_example (i : int) : int = + let closure : int -> int = fun (j : int) -> i + j in + closure i +``` + + + + +```reasonligo +let closure_example = (i : int) : int => { + let closure = (j: int): int => i + j; + closure(i); +}; +``` + + + ## Recursive function LIGO functions are not recursive by default, the user need to indicate that the function is recursive.