<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">

<html>

<!--(==============================================================)-->
<!--(Document created with RoboEditor. )============================-->
<!--(==============================================================)-->

<head>

<title>DECL Region</title>

<!--(Meta)==========================================================-->

<meta http-equiv=content-type content="text/html; charset=windows-1252">
<meta name=date content="03 13, 2002 11:00:33 PM">
<meta name=generator content="RoboHELP by eHelp Corporation - www.ehelp.com">
<meta name=generator-major-version content=0.1>
<meta name=generator-minor-version content=1>
<meta name=filetype content=kadov>
<meta name=filetype-version content=1>
<meta name=page-count content=1>
<meta name=layout-height content=757>
<meta name=layout-width content=1024>


<!--(Links)=========================================================-->

<link rel="StyleSheet" href="default.css">



</head>

<!--(Body)==========================================================-->


<body>

<h1>DECL Region</h1>

<p>The DECL Region is where you define your own functions in NLP++. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->It 
 is delimited by @DECL and optionally by @@DECL. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->When 
 present, it must be the first region in a pass file.</p>

<p>With VisualText 1.2 and later, functions can take parameters with the 
 <span style="color: #ff0000; font-weight: bold;">L</span> local variable, 
 as well as return values and call themselves recursively. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->In 
 addition, you may use the special NLP++ variable references to pass information 
 to and from functions. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->Depending 
 on where a function is called from, it can appropriately handle the <span 
 style="font-weight: bold; color: #ff0000;">S</span>, <span style="font-weight: bold; color: #ff0000;">N</span>, 
 and <span style="font-weight: bold; color: #ff0000;">X</span> variable 
 references in addition to the global, or <span style="font-weight: bold; color: #ff0000;">G</span>, 
 variable reference. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->The 
 return type of functions can vary dynamically -- in fact, the same function 
 could return different types at different times. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->Multi-valued 
 variables (i.e., arrays) can be used to have a function return multiple 
 values.</p>

<p>Recursive functions work as expected. <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->Also, 
 you may call a function in an earlier pass than the pass in which it is 
 defined (i.e., forward reference is ok). <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->NLP++ 
 functions have syntax similar to C/C++ functions.</p>

<p>&lt;function definition&gt; ::= &lt;id&gt; \( &lt;local vars&gt; <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->\) 
 <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<!--kadov_tag{{</spaces>}}-->\{ 
 &lt;statements&gt; \}<br>
&lt;local vars&gt; ::= &lt;local vars&gt; \, &lt;local var&gt; <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->| 
 &lt;local var&gt; <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->| 
 <!--kadov_tag{{<spaces>}}-->&nbsp;<!--kadov_tag{{</spaces>}}-->(empty)<br>
&lt;local var&gt; ::= 'L' \( &lt;string&gt; \)<br>
&lt;statement&gt; ::= &lt;return statement&gt;<br>
&lt;return statement&gt; ::= 'return' &lt;expr&gt; \; <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<!--kadov_tag{{</spaces>}}-->| 
 <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<!--kadov_tag{{</spaces>}}-->'return' 
 \;<br>&nbsp;</p>

<p>An example follows.</p>

<p><span style="font-weight: bold; color: #0000ff;">@DECL</span><br>
<br>
myfunction(<span style="color: #ff0000; font-weight: bold;">L</span>(<span 
 style="color: #ff00ff;">&quot;var&quot;</span>)) <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<span 
 style="color: #008000;">&nbsp;<!--kadov_tag{{</spaces>}}--># Define your 
 function.</span><br>
{<span style="color: #ff00ff;"><br>
&quot;output.txt&quot;</span> &lt;&lt; <span style="color: #ff00ff;">&quot;Entering 
 myfunction.&quot;</span> &lt;&lt; <span style="color: #ff00ff;">&quot;\n&quot;</span>;<span 
 style="font-weight: bold; color: #ff0000;"><br>
G</span>(<span style="color: #ff00ff;">&quot;tmp&quot;</span>) = <span 
 style="font-weight: bold; color: #ff0000;">L</span>(<span style="color: #ff00ff;">&quot;var&quot;</span>); 
 <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<span style="color: #008000;"><!--kadov_tag{{</spaces>}}--># 
 Assign value to global variable.</span><span style="font-weight: bold; color: #ff0000;"><br>
L</span>(<span style="color: #ff00ff;">&quot;tmp&quot;</span>) = <span 
 style="font-weight: bold; color: #ff0000;">L</span>(<span style="color: #ff00ff;">&quot;var&quot;</span>); 
 <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<span style="color: #008000;"><!--kadov_tag{{</spaces>}}--># 
 Assign value to local variable.</span><br>
return <span style="font-weight: bold; color: #ff0000;">L</span>(<span 
 style="color: #ff00ff;">&quot;tmp&quot;</span>) * 2; <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<span 
 style="color: #008000;"><!--kadov_tag{{</spaces>}}--># Return a value.</span><br>
}</p>

<p style="color: #0000ff; font-weight: bold;">@CODE</p>

<p><span style="color: #ff00ff;">&quot;output.txt&quot;</span> &lt;&lt; 
 myfunction(3) &lt;&lt; <span style="color: #ff00ff;">&quot;\n&quot;</span>; 
 <!--kadov_tag{{<spaces>}}-->&nbsp;&nbsp;<span style="color: #008000;"><!--kadov_tag{{</spaces>}}--># 
 Call your function.</span><span style="color: #0000ff; font-weight: bold;"><br>
<br>
@@CODE</span></p>

<p>This function call returns and outputs the number &quot;6&quot; to the 
 file &quot;output.txt&quot;.</p>

<h2>See Also</h2>

<p><a href="Declare.htm">Declare Zone</a></p>

</body>

</html>
