Functions

Figure 78. VarDecl

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 175. 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 176. 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 177. 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 178. 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!