How it works

The Instruction operation "function" performs a specific task separately from the main program, functions may take any number of named parameters as arguments. Also known as a subroutine or subprogram in other languages. The first input of a function operation must declare the function source, subsequent inputs provide the named parameters.

"Function" examples

Example 1: Simple Function Call

The example below shows a simple function being called by Obyx, we need two files, the function caller "fn-caller.obyx", that as the name suggests calls the function and then displays it onto the screen and "function.ixml", which is the actual function file.

The first instruction has a value of "Calling a " and the second instruction calls the function which is an external file.

fn-caller.obyx:
<!-- simple call to a function -->
<instruction operation="append" xmlns="http://www.obyx.org">
    <input value="Calling a " />
    <input>
        <instruction operation="function">
            <input space="file" value="function.ixml"  />   
        </instruction>
    </input>
</instruction>
Calling a Simple Function!

The instruction in our function below has a value of "Simple Function!". Both are output to screen returning "Calling a Simple Function!".

function.ixml:
<instruction xmlns="http://www.obyx.org">
     <input>
         Simple Function!
     </input>
 </instruction>

Anotehr example of a function.

This example function shows how to provide a check for emptiness and existence, while setting a default:

<comparison operation="exists" note="ckfunc.xml" xmlns="http://www.obyx.org">
	<comparate space="parm" value="number" />
	<ontrue>
		<comparison invert="true" operation="empty">
			<comparate space="parm" value="number" encoder="digits" />
			<ontrue space="parm" value="number" encoder="digits" />
			<onfalse>
				<comparison operation="empty">
					<comparate space="parm" value="default" />
					<ontrue space="parm" value="default" />
					<onfalse value="3000" />
				</comparison>
			</onfalse>
		</comparison> 
	</ontrue>
	<onfalse>
		<comparison operation="empty">
			<comparate space="parm" value="default" />
			<ontrue space="parm" value="default" />
			<onfalse value="3001" />
		</comparison>
	</onfalse>
</comparison>

Then, we can call it in any of the following manners:

<instruction operation="function" xmlns="http://www.obyx.org">
	<input space="file" value="ckfunc.xml" />
</instruction>
3001
<instruction operation="function" xmlns="http://www.obyx.org">
	<input space="file" value="ckfunc.xml" />
	<input value="600" name="default" />
</instruction>
600
<instruction operation="function" xmlns="http://www.obyx.org">
	<input space="file" value="ckfunc.xml" />
	<input value="500" name="number" />
</instruction>
500
<instruction operation="function" xmlns="http://www.obyx.org">
	<input space="file" value="ckfunc.xml" />
	<input value="300" name="number" />
	<input value="201" name="default" />
</instruction>
300



Last Modified: Thu, 15 Jan 2015