The saxon:memo-function option declaration

Saxon provides an option declaration to treat the immediately following function as a memo-function. This takes the form shown in the following example:

declare namespace saxon="http://saxon.sf.net/"; declare option saxon:memo-function "true"; declare function local:factorial($n as xs:integer) as xs:integer { local:factorial($n - 1) * n };

Alternatively:

declare namespace saxon="http://saxon.sf.net/"; declare %saxon:memo-function function local:factorial($n as xs:integer) as xs:integer { local:factorial($n - 1) * n };

A memo function remembers the results of previous calls, so if it is called twice with the same arguments, it will not repeat the computation, but return the previous result.

The allowed values of the option are "true" and "false" (the default is false), and any other value is ignored with a warning.