Difference between revisions of "Recital Functions"

From Recital Documentation Wiki
Jump to: navigation, search
 
(Recital Functions)
Line 1: Line 1:
 
==Recital Functions==
 
==Recital Functions==
 +
====Defining a Function====
 +
The [[FUNCTION|function]] command is used to declare a User Defined Function (UDF).  Recital UDFs can be used wherever a built-in Recital function can be used.
 +
 +
A UDF can have a variable number of parameters passed to it.  These are assigned to private variables in the the <parameter-list> declaration or [[PARAMETERS|parameters]] statement.  The [[PARAMETERS()|parameters()]] function can be used to determine how many actual parameters were specified.
 +
 +
The [[FUNCTION|function]] command is terminated with an [[ENDFUNC|endfunc]] or [[RETURN|return]] statement.
 +
 +
<pre>
 +
function <name as character>[(<parameters as list>)]
 +
[parameters <parameters as list>]
 +
[return <value as expression> | endfunc]
 +
</pre>
 +
 +
====Calling a Function====
 +
Functions can be included in program files, as well as in procedure library files.  The functions in a procedure library file are made known to the Recital process by using the [[SET PROCEDURE|set procedure]] command.
 +
 +
<pre>
 +
set procedure to [<filename as character> [ADDITIVE]]
 +
</pre>
 +
 +
Functions can be called like built-in functions: postfixing the name of the function with brackets containing any arguments, e.g.
 +
 +
<code lang="recital">
 +
myudf(m_var,"Hello World",123.45,{12/03/2010})
 +
</code>
 +
 +
In this case, parameters are passed by ''value'': a copy of the memory variable is passed to the module and the original memory variable is not accessible within the called module.
 +
 +
Alternatively, the function can be called using the [[DO|do]] command and specifying the arguments in the [[DO|with]] clause, e.g.
 +
 +
<code lang="recital">
 +
do myudf with m_var,"Hello World",123.45,{12/03/2010}
 +
</code>
 +
 +
With [[DO|do]] command, parameters are passed by ''reference'': the called module is given the address of the memory variable so the memory variable itself can be altered.
 +
 
===What is a Recital Function===
 
===What is a Recital Function===
 
===How to Write a Recital Function===
 
===How to Write a Recital Function===

Revision as of 12:10, 12 March 2010

Recital Functions

Defining a Function

The function command is used to declare a User Defined Function (UDF). Recital UDFs can be used wherever a built-in Recital function can be used.

A UDF can have a variable number of parameters passed to it. These are assigned to private variables in the the <parameter-list> declaration or parameters statement. The parameters() function can be used to determine how many actual parameters were specified.

The function command is terminated with an endfunc or return statement.

function <name as character>[(<parameters as list>)]
[parameters <parameters as list>]
[return <value as expression> | endfunc]

Calling a Function

Functions can be included in program files, as well as in procedure library files. The functions in a procedure library file are made known to the Recital process by using the set procedure command.

set procedure to [<filename as character> [ADDITIVE]] 

Functions can be called like built-in functions: postfixing the name of the function with brackets containing any arguments, e.g.

myudf(m_var,"Hello World",123.45,{12/03/2010})

In this case, parameters are passed by value: a copy of the memory variable is passed to the module and the original memory variable is not accessible within the called module.

Alternatively, the function can be called using the do command and specifying the arguments in the with clause, e.g.

do myudf with m_var,"Hello World",123.45,{12/03/2010}

With do command, parameters are passed by reference: the called module is given the address of the memory variable so the memory variable itself can be altered.

What is a Recital Function

How to Write a Recital Function

Returning a Value from a Recital Function

Passing Parameters to a Recital Function

Calling Recital Functions

Passing Parameters by Reference

Returning Values by Reference

Variable Scope

Built-in Functions

Extending with Functions Developed in C/C++

Summary