Statements function And call
A function statement defines a function that can either be called from a call statement or used in an expression with the function operator '@'. Optionally, arguments can be passed to the function which can then be used as local variables. When calling the function, these augments may be given values or omitted. An argument can be given a default value when the function is defined.
When the function is run, the arguments are treated as local variables. An addition local variable named 'result' is created, and this is the value given to the function when it used in an expression. Additional variables that are created within the function will be local and their values lost when the function completes. Variables created outside of the function cannot be seen whilst inside.
function Statement | ||
---|---|---|
Format | Example | Output |
function name { statements ... } call name; |
function wr_today { write string.g:dmy today; } ... call wr_today; | 21 May 2017 |
function name { ... result = expr; ... } write @name; |
function get_today { result = "(" + string.g:dmy today + ")"; } ... write @get_today; | (21 May 2017) |
function name(arg=value, arg=value) { statements ... } call name(value1, value2); |
function wr_range_plus(start, duration = 7){ write string.g:dmy( start .. start + duration ); } ... call wr_range_plus(date.g:dmy "19sep1948", 14); | 19 Sep 1948 .. 3 Oct 1948 |
function name(arg=value, arg=value) { ... result = expr; ... } write @name(value1, value2); |
function range_plus(start, duration = 7){ result = start .. start + duration; } ... write string.g:dmy @range_plus(2432814); | 19 Sep 1948 .. 26 Sep 1948 |
Written when today = "g:dmy# 21 May 2017" |