Function

A special type of Private Method, called a Private Function, is intended to return a single value or multiple values simultaneously.

Description:

Executing Return will return the value assigned to it to the assignment Field. If it requires solving, it must be inside of () like other solved values in Moxie. If it is a simple value that does not require solving, it then should not be in (). Return will also Exit the Function at the same time.

Unlike Methods, the MethodName.Output Query is not preserved after the Function has ended. This allows it to be  called many times over without having the worry about Output Query clean up as is required by Methods. Only the returned value which is assigned via Return is saved (unless the Function creates or interacts with other Queries beyond MethodName.Output of its choosing by design.)

Private Functions are like Private Methods, using the same call structure and stack, and are therefore are not accessible within expressions. Typed Functions (using $ and % symbols at the end of their name) that will have no access to other Query memory space, but could then be called from expressions, may be added to MOX in the future depending on the level of demand for them.

The Return command may be used in Private Methods, Public Methods, or Remote Methods if desired, as its internal workings are such that: it Resets the Output Query (not necessarily the Work Query), Creates a new Field named Return, assigns the Parameter value to it, and performs an Exit. It is expected that future version of Moxie will have Public Functions and Remote Functions. Therefore using the Return command in them and standardizing on a single Field named Return as the function result conduit is encouraged.

The automatic cleanup of the Output Query described above when calling a Function is the responsibility of the caller, and is handled for you when calling a Function within the same Procedure using an assignment. This behaviour could be avoided by calling the Function like a Method (ie without an assignment) instead. The information in this last paragraph is provided for documentation sake only, it is not recommended to make use of it ;)

Example:

    Function MyFunc(pOne, pTwo)
        Html "Hello, World!"
        Return (pOne & ", " & pTwo & "!")
    End Function
    
    [New] Test = MyFunc "Hello", "World"