Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 315

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Overloading and Autoloading - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<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:&nbsp;<a rel="next" accesskey="n" href="Function-Locking.html#Function-Locking">Function Locking</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Private-Functions.html#Private-Functions">Private Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Function-Files.html#Function-Files">Function Files</a>
<hr>
</div>

<h4 class="subsection">11.7.4 Overloading and Autoloading</h4>

<p>The <code>dispatch</code> function can be used to alias one function name to
another.  It can be used to alias all calls to a particular function name
to another function, or the alias can be limited to only a particular
variable type.  Consider the example

<pre class="example">     function y = spsin (x)
       printf ("Calling spsin\n");
       fflush(stdout);
       y = spfun ("sin", x);
     endfunction
     
     dispatch ("sin", "spsin", "sparse matrix");
     y0 = sin(eye(3));
     y1 = sin(speye(3));
</pre>
   <p class="noindent">which aliases the user-defined function <code>spsin</code> to <code>sin</code>, but only for real sparse
matrices.  Note that the builtin <code>sin</code> already correctly treats
sparse matrices and so this example is only illustrative.

<!-- ./DLD-FUNCTIONS/dispatch.cc -->
   <p><a name="doc_002ddispatch"></a>

<div class="defun">
&mdash; Loadable Function:  <b>dispatch</b> (<var>f, r, type</var>)<var><a name="index-dispatch-636"></a></var><br>
<blockquote>
        <p>Replace the function <var>f</var> with a dispatch so that function <var>r</var>
is called when <var>f</var> is called with the first argument of the named
<var>type</var>.  If the type is <var>any</var> then call <var>r</var> if no other type
matches.  The original function <var>f</var> is accessible using
<code>builtin (</code><var>f</var><code>, ...)</code>.

        <p>If <var>r</var> is omitted, clear dispatch function associated with <var>type</var>.

        <p>If both <var>r</var> and <var>type</var> are omitted, list dispatch functions
for <var>f</var>. 
<!-- 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_002dbuiltin.html#doc_002dbuiltin">builtin</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/dispatch.cc -->
   <p><a name="doc_002dbuiltin"></a>

<div class="defun">
&mdash; Loadable Function: [<small class="dots">...</small>] <b>builtin</b> (<var>f, <small class="dots">...</small></var>)<var><a name="index-builtin-637"></a></var><br>
<blockquote><p>Call the base function <var>f</var> even if <var>f</var> is overloaded to
some other function for the given type signature. 
<!-- 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_002ddispatch.html#doc_002ddispatch">dispatch</a>. 
</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.

<!-- parse.cc -->
   <p><a name="doc_002dautoload"></a>

<div class="defun">
&mdash; Built-in Function:  <b>autoload</b> (<var>function, file</var>)<var><a name="index-autoload-638"></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>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>