Product SiteDocumentation Site

6.3. Functions

VarDecl
Figure 6.10. VarDecl

You can define your own functions in the prolog. These user-defined functions must be prefixed with local:, both in the declaration and when called.
Remember than types are optional, and if you do not specify any, item* is assumed, both for parameters and for the return type.
Example 6.6. An external global variable with a default value
declare function local:say-hello($x) { "Hello, " || $x || "!" };
local:say-hello("Mister Spock")
Result (run with Zorba):
Hello, Mister Spock!

Example 6.7. An external global variable with a default value
declare function local:say-hello($x as string) { "Hello, " || $x || "!" };
local:say-hello("Mister Spock")
Result (run with Zorba):
Hello, Mister Spock!

Example 6.8. An external global variable with a default value
declare function local:say-hello($x as string) as string { "Hello, " || $x || "!" };
local:say-hello("Mister Spock")
Result (run with Zorba):
Hello, Mister Spock!

If you do specify types, an error is raised in case of a mismatch
Example 6.9. An external global variable with a default value
declare function local:say-hello($x) { "Hello, " || $x || "!" }; 
local:say-hello(1)
Result (run with Zorba):
Hello, 1!