1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Subfunctions (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Subfunctions (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Subfunctions (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Function-Files.html" rel="up" title="Function Files">
<link href="Private-Functions.html" rel="next" title="Private Functions">
<link href="Manipulating-the-Load-Path.html" rel="prev" title="Manipulating the Load Path">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Subfunctions">
<div class="nav-panel">
<p>
Next: <a href="Private-Functions.html" accesskey="n" rel="next">Private Functions</a>, Previous: <a href="Manipulating-the-Load-Path.html" accesskey="p" rel="prev">Manipulating the Load Path</a>, Up: <a href="Function-Files.html" accesskey="u" rel="up">Function Files</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Subfunctions-1"><span>11.10.2 Subfunctions<a class="copiable-link" href="#Subfunctions-1"> ¶</a></span></h4>
<p>A function file may contain secondary functions called
<em class="dfn">subfunctions</em>. These secondary functions are only visible to the
other functions in the same function file. For example, a file
<samp class="file">f.m</samp> containing
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">function f ()
printf ("in f, calling g\n");
g ()
endfunction
function g ()
printf ("in g, calling h\n");
h ()
endfunction
function h ()
printf ("in h\n")
endfunction
</pre></div></div>
<p>defines a main function <code class="code">f</code> and two subfunctions. The
subfunctions <code class="code">g</code> and <code class="code">h</code> may only be called from the main
function <code class="code">f</code> or from the other subfunctions, but not from outside
the file <samp class="file">f.m</samp>.
</p>
<a class="anchor" id="XREFlocalfunctions"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-localfunctions"><span><code class="def-type"><var class="var">subfcn_list</var> =</code> <strong class="def-name">localfunctions</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-localfunctions"> ¶</a></span></dt>
<dd><p>Return a list of all local functions, i.e., subfunctions, within the current
file.
</p>
<p>The return value is a column cell array of function handles to all local
functions accessible from the function from which <code class="code">localfunctions</code> is
called. Nested functions are <em class="emph">not</em> included in the list.
</p>
<p>If the call is from the command line, an anonymous function, or a script,
the return value is an empty cell array.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Function-Handles.html#XREFfunctions">functions</a>.
</p></dd></dl>
</div>
</body>
</html>
|