aboutsummaryrefslogtreecommitdiff
path: root/doc/language/cpsc-keyword-function.7.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/language/cpsc-keyword-function.7.md')
-rw-r--r--doc/language/cpsc-keyword-function.7.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/language/cpsc-keyword-function.7.md b/doc/language/cpsc-keyword-function.7.md
new file mode 100644
index 0000000..c37754c
--- /dev/null
+++ b/doc/language/cpsc-keyword-function.7.md
@@ -0,0 +1,41 @@
+% CPSC-KEYWORD-FUNCTION(7)
+
+# NAME
+
+cpsc-keyword-function - define a function that returns a value
+
+# SYNOPSIS
+
+```text
+FUNCTION name(parameters) RETURNS type
+ statements
+ RETURN expression
+ENDFUNCTION
+```
+
+# DESCRIPTION
+
+Call a function in an expression as `name(arguments)`. A call may precede its
+top-level definition. RETURNS specifies the result type; omitting it defaults
+to INTEGER. RETURN supplies a value of that type. Whole-array results are
+unsupported.
+
+Parameters use `name : type`, optionally prefixed by BYVAL. BYVAL is the
+default; BYREF is forbidden for functions (guide section 8.3).
+Array parameters accept `ARRAY OF type` (one dimension) or
+`ARRAY[lower:upper, ...] OF type` (integer literal bounds).
+BYVAL arrays are copied. RETURNS, RETURN, BYVAL, and ENDFUNCTION belong here.
+
+# EXAMPLE
+
+```text
+FUNCTION Double(Value : INTEGER) RETURNS INTEGER
+ RETURN Value * 2
+ENDFUNCTION
+OUTPUT Double(4)
+```
+
+# SEE ALSO
+
+[cpsc-language-overview(7)](cpsc-language-overview.7.md), [cpsc-keyword-procedure(7)](cpsc-keyword-procedure.7.md), [cpsc-keyword-call(7)](cpsc-keyword-call.7.md).
+