<html lang="en"> <head> <title>Overloading and Autoloading - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Function-Files.html#Function-Files" title="Function Files"> <link rel="prev" href="Private-Functions.html#Private-Functions" title="Private Functions"> <link rel="next" href="Function-Locking.html#Function-Locking" title="Function Locking"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Overloading-and-Autoloading"></a> <p> Next: <a rel="next" accesskey="n" href="Function-Locking.html#Function-Locking">Function Locking</a>, Previous: <a rel="previous" accesskey="p" href="Private-Functions.html#Private-Functions">Private Functions</a>, Up: <a rel="up" accesskey="u" href="Function-Files.html#Function-Files">Function Files</a> <hr> </div> <h4 class="subsection">11.8.4 Overloading and Autoloading</h4> <p>Functions can be overloaded to work with different input arguments. For example, the operator '+' has been overloaded in Octave to work with single, double, uint8, int32, and many other arguments. The preferred way to overload functions is through classes and object oriented programming (see <a href="Function-Overloading.html#Function-Overloading">Function Overloading</a>). Occasionally, however, one needs to undo user overloading and call the default function associated with a specific type. The <code>builtin</code> function exists for this purpose. <!-- builtin src/oct-parse.cc --> <p><a name="doc_002dbuiltin"></a> <div class="defun"> — Loadable Function: [<small class="dots">...</small>] <b>builtin</b> (<var>f, <small class="dots">...</small></var>)<var><a name="index-builtin-779"></a></var><br> <blockquote><p>Call the base function <var>f</var> even if <var>f</var> is overloaded to another function for the given type signature. </p></blockquote></div> <p>A single dynamically linked file might define several functions. However, as Octave searches for functions based on the functions filename, Octave needs a manner in which to find each of the functions in the dynamically linked file. On operating systems that support symbolic links, it is possible to create a symbolic link to the original file for each of the functions which it contains. <p>However, there is at least one well known operating system that doesn't support symbolic links. Making copies of the original file for each of the functions is undesirable as it increases the amount of disk space used by Octave. Instead Octave supplies the <code>autoload</code> function, that permits the user to define in which file a certain function will be found. <!-- autoload src/oct-parse.cc --> <p><a name="doc_002dautoload"></a> <div class="defun"> — Built-in Function: <b>autoload</b> (<var>function, file</var>)<var><a name="index-autoload-780"></a></var><br> <blockquote><p>Define <var>function</var> to autoload from <var>file</var>. <p>The second argument, <var>file</var>, should be an absolute file name or a file name in the same directory as the function or script from which the autoload command was run. <var>file</var> should not depend on the Octave load path. <p>Normally, calls to <code>autoload</code> appear in PKG_ADD script files that are evaluated when a directory is added to the Octave's load path. To avoid having to hardcode directory names in <var>file</var>, if <var>file</var> is in the same directory as the PKG_ADD script then <pre class="example"> autoload ("foo", "bar.oct"); </pre> <p class="noindent">will load the function <code>foo</code> from the file <code>bar.oct</code>. The above when <code>bar.oct</code> is not in the same directory or uses like <pre class="example"> autoload ("foo", file_in_loadpath ("bar.oct")) </pre> <p class="noindent">are strongly discouraged, as their behavior might be unpredictable. <p>With no arguments, return a structure containing the current autoload map. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dPKG_005fADD.html#doc_002dPKG_005fADD">PKG_ADD</a>. </p></blockquote></div> </body></html>