annotate doc/interpreter/func.txi @ 19074:0850b5212619

doc: Add @nospell macro around proper names in documentation. * aspell-octave.en.pws: Remove proper names from Octave's custom dictionary. * doc/interpreter/audio.txi, doc/interpreter/diagperm.txi, doc/interpreter/diffeq.txi, doc/interpreter/emacs.txi, doc/interpreter/func.txi, doc/interpreter/geometry.txi, doc/interpreter/intro.txi, doc/interpreter/linalg.txi, doc/interpreter/numbers.txi, doc/interpreter/preface.txi, doc/interpreter/quad.txi, doc/interpreter/sparse.txi, libinterp/corefcn/colloc.cc, libinterp/corefcn/ellipj.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/hess.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/sqrtm.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/symrcm.cc, scripts/general/quadgk.m, scripts/general/quadl.m, scripts/linear-algebra/commutation_matrix.m, scripts/linear-algebra/condest.m, scripts/linear-algebra/duplication_matrix.m, scripts/linear-algebra/expm.m, scripts/linear-algebra/housh.m, scripts/linear-algebra/krylov.m, scripts/linear-algebra/onenormest.m, scripts/linear-algebra/qzhess.m, scripts/optimization/fminsearch.m, scripts/optimization/glpk.m, scripts/signal/arch_fit.m, scripts/signal/bartlett.m, scripts/signal/blackman.m, scripts/signal/diffpara.m, scripts/signal/durbinlevinson.m, scripts/signal/hamming.m, scripts/signal/hanning.m, scripts/sparse/eigs.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/specfun/ellipke.m, scripts/special-matrix/gallery.m, scripts/special-matrix/invhilb.m, scripts/statistics/base/quantile.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m: Add @nospell macro around proper names in documentation.
author Rik <rik@octave.org>
date Thu, 21 Aug 2014 15:57:18 -0700
parents ff820f92cbb5
children be8a12acb20a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1 @c Copyright (C) 1996-2013 John W. Eaton
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
2 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
3 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
4 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
5 @c Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
6 @c under the terms of the GNU General Public License as published by the
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
7 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
8 @c your option) any later version.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
9 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
13 @c for more details.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
14 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
15 @c You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
16 @c along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
17 @c <http://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
18
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
19 @node Functions and Scripts
9032
349616d9c38e Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
20 @chapter Functions and Scripts
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
21 @cindex defining functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
22 @cindex user-defined functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
23 @cindex functions, user-defined
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
24 @cindex script files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
25
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
26 Complicated Octave programs can often be simplified by defining
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
27 functions. Functions can be defined directly on the command line during
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
28 interactive Octave sessions, or in external files, and can be called just
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
29 like built-in functions.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
30
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
31 @menu
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
32 * Introduction to Function and Script Files::
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
33 * Defining Functions::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
34 * Multiple Return Values::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
35 * Variable-length Argument Lists::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
36 * Ignoring Arguments::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
37 * Variable-length Return Lists::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
38 * Returning from a Function::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
39 * Default Arguments::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
40 * Function Files::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
41 * Script Files::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
42 * Function Handles Anonymous Functions Inline Functions::
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
43 * Commands::
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
44 * Organization of Functions::
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
45 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
46
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
47 @node Introduction to Function and Script Files
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
48 @section Introduction to Function and Script Files
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
49
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
50 There are seven different things covered in this section.
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
51 @enumerate
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
52 @item
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
53 Typing in a function at the command prompt.
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
54
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
55 @item
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
56 Storing a group of commands in a file --- called a script file.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
57
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
58 @item
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
59 Storing a function in a file---called a function file.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
60
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
61 @item
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
62 Subfunctions in function files.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
63
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
64 @item
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
65 Multiple functions in one script file.
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
66
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
67 @item
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
68 Private functions.
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
69
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
70 @item
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
71 Nested functions.
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
72 @end enumerate
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
73
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
74 Both function files and script files end with an extension of .m, for
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
75 @sc{matlab} compatibility. If you want more than one independent
14442
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
76 functions in a file, it must be a script file (@pxref{Script Files}),
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
77 and to use these functions you must execute the script file before you
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
78 can use the functions that are in the script file.
c1f9b54350f9 doc: improve description of functions and scripts
Doug Stewart <doug.dastew@gmail.com>
parents: 14175
diff changeset
79
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
80 @node Defining Functions
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
81 @section Defining Functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
82 @cindex @code{function} statement
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
83 @cindex @code{endfunction} statement
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
84
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
85 In its simplest form, the definition of a function named @var{name}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
86 looks like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
87
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
88 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
89 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
90 function @var{name}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
91 @var{body}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
92 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
93 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
94 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
95
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
96 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
97 A valid function name is like a valid variable name: a sequence of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
98 letters, digits and underscores, not starting with a digit. Functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
99 share the same pool of names as variables.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
100
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
101 The function @var{body} consists of Octave statements. It is the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
102 most important part of the definition, because it says what the function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
103 should actually @emph{do}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
104
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
105 For example, here is a function that, when executed, will ring the bell
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
106 on your terminal (assuming that it is possible to do so):
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
107
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
108 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
109 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
110 function wakeup
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
111 printf ("\a");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
112 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
113 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
114 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
115
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
116 The @code{printf} statement (@pxref{Input and Output}) simply tells
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17152
diff changeset
117 Octave to print the string @qcode{"\a"}. The special character @samp{\a}
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
118 stands for the alert character (ASCII 7). @xref{Strings}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
119
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
120 Once this function is defined, you can ask Octave to evaluate it by
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
121 typing the name of the function.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
122
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
123 Normally, you will want to pass some information to the functions you
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
124 define. The syntax for passing parameters to a function in Octave is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
125
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
126 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
127 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
128 function @var{name} (@var{arg-list})
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
129 @var{body}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
130 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
131 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
132 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
133
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
134 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
135 where @var{arg-list} is a comma-separated list of the function's
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
136 arguments. When the function is called, the argument names are used to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
137 hold the argument values given in the call. The list of arguments may
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
138 be empty, in which case this form is equivalent to the one shown above.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
139
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
140 To print a message along with ringing the bell, you might modify the
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
141 @code{wakeup} to look like this:
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
142
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
143 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
144 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
145 function wakeup (message)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
146 printf ("\a%s\n", message);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
147 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
148 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
149 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
150
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
151 Calling this function using a statement like this
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
152
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
153 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
154 wakeup ("Rise and shine!");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
155 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
156
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
157 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
158 will cause Octave to ring your terminal's bell and print the message
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
159 @samp{Rise and shine!}, followed by a newline character (the @samp{\n}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
160 in the first argument to the @code{printf} statement).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
161
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
162 In most cases, you will also want to get some information back from the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
163 functions you define. Here is the syntax for writing a function that
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
164 returns a single value:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
165
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
166 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
167 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
168 function @var{ret-var} = @var{name} (@var{arg-list})
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
169 @var{body}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
170 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
171 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
172 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
173
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
174 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
175 The symbol @var{ret-var} is the name of the variable that will hold the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
176 value to be returned by the function. This variable must be defined
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
177 before the end of the function body in order for the function to return
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
178 a value.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
179
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
180 Variables used in the body of a function are local to the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
181 function. Variables named in @var{arg-list} and @var{ret-var} are also
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
182 local to the function. @xref{Global Variables}, for information about
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
183 how to access global variables inside a function.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
184
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
185 For example, here is a function that computes the average of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
186 elements of a vector:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
187
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
188 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
189 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
190 function retval = avg (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
191 retval = sum (v) / length (v);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
192 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
193 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
194 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
195
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
196 If we had written @code{avg} like this instead,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
197
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
198 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
199 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
200 function retval = avg (v)
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3760
diff changeset
201 if (isvector (v))
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
202 retval = sum (v) / length (v);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
203 endif
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
204 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
205 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
206 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
207
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
208 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
209 and then called the function with a matrix instead of a vector as the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
210 argument, Octave would have printed an error message like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
211
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
212 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
213 @group
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7984
diff changeset
214 error: value on right hand side of assignment is undefined
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
215 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
216 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
217
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
218 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
219 because the body of the @code{if} statement was never executed, and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
220 @code{retval} was never defined. To prevent obscure errors like this,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
221 it is a good idea to always make sure that the return variables will
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
222 always have values, and to produce meaningful error messages when
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
223 problems are encountered. For example, @code{avg} could have been
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
224 written like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
225
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
226 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
227 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
228 function retval = avg (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
229 retval = 0;
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3760
diff changeset
230 if (isvector (v))
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
231 retval = sum (v) / length (v);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
232 else
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
233 error ("avg: expecting vector argument");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
234 endif
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
235 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
236 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
237 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
238
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
239 There is still one additional problem with this function. What if it is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
240 called without an argument? Without additional error checking, Octave
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
241 will probably print an error message that won't really help you track
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
242 down the source of the error. To allow you to catch errors like this,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
243 Octave provides each function with an automatic variable called
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
244 @code{nargin}. Each time a function is called, @code{nargin} is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
245 automatically initialized to the number of arguments that have actually
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
246 been passed to the function. For example, we might rewrite the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
247 @code{avg} function like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
248
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
249 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
250 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
251 function retval = avg (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
252 retval = 0;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
253 if (nargin != 1)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
254 usage ("avg (vector)");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
255 endif
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3760
diff changeset
256 if (isvector (v))
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
257 retval = sum (v) / length (v);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
258 else
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
259 error ("avg: expecting vector argument");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
260 endif
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
261 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
262 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
263 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
264
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
265 Although Octave does not automatically report an error if you call a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
266 function with more arguments than expected, doing so probably indicates
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
267 that something is wrong. Octave also does not automatically report an
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
268 error if a function is called with too few arguments, but any attempt to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
269 use a variable that has not been given a value will result in an error.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
270 To avoid such problems and to provide useful messages, we check for both
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
271 possibilities and issue our own error message.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
272
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4466
diff changeset
273 @DOCSTRING(nargin)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
274
6558
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
275 @DOCSTRING(inputname)
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
276
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3294
diff changeset
277 @DOCSTRING(silent_functions)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
278
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
279 @node Multiple Return Values
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
280 @section Multiple Return Values
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
281
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
282 Unlike many other computer languages, Octave allows you to define
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
283 functions that return more than one value. The syntax for defining
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
284 functions that return multiple values is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
285
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
286 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
287 @group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
288 function [@var{ret-list}] = @var{name} (@var{arg-list})
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
289 @var{body}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
290 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
291 @end group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
292 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
293
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
294 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
295 where @var{name}, @var{arg-list}, and @var{body} have the same meaning
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
296 as before, and @var{ret-list} is a comma-separated list of variable
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
297 names that will hold the values returned from the function. The list of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
298 return values must have at least one element. If @var{ret-list} has
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
299 only one element, this form of the @code{function} statement is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
300 equivalent to the form described in the previous section.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
301
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
302 Here is an example of a function that returns two values, the maximum
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
303 element of a vector and the index of its first occurrence in the vector.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
304
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
305 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
306 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
307 function [max, idx] = vmax (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
308 idx = 1;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
309 max = v (idx);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
310 for i = 2:length (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
311 if (v (i) > max)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
312 max = v (i);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
313 idx = i;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
314 endif
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
315 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
316 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
317 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
318 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
319
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
320 In this particular case, the two values could have been returned as
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
321 elements of a single array, but that is not always possible or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
322 convenient. The values to be returned may not have compatible
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
323 dimensions, and it is often desirable to give the individual return
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
324 values distinct names.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
325
13749
62d1f56b0be7 New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12642
diff changeset
326 It is possible to use the @code{nthargout} function to obtain only some
14038
b0cdd60db5e5 doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13852
diff changeset
327 of the return values or several at once in a cell array.
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16772
diff changeset
328 @xref{Cell Array Objects}.
13749
62d1f56b0be7 New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12642
diff changeset
329
62d1f56b0be7 New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12642
diff changeset
330 @DOCSTRING(nthargout)
62d1f56b0be7 New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12642
diff changeset
331
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
332 In addition to setting @code{nargin} each time a function is called,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
333 Octave also automatically initializes @code{nargout} to the number of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
334 values that are expected to be returned. This allows you to write
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
335 functions that behave differently depending on the number of values that
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
336 the user of the function has requested. The implicit assignment to the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
337 built-in variable @code{ans} does not figure in the count of output
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
338 arguments, so the value of @code{nargout} may be zero.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
339
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
340 The @code{svd} and @code{lu} functions are examples of built-in
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
341 functions that behave differently depending on the value of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
342 @code{nargout}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
343
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
344 It is possible to write functions that only set some return values. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
345 example, calling the function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
346
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
347 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
348 @group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
349 function [x, y, z] = f ()
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
350 x = 1;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
351 z = 2;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
352 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
353 @end group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
354 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
355
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
356 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
357 as
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
358
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
359 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
360 [a, b, c] = f ()
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
361 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
362
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
363 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
364 produces:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
365
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
366 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
367 @group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
368 a = 1
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
369
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
370 b = [](0x0)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
371
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
372 c = 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
373 @end group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
374 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
375
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
376 @noindent
6501
68f3125f6e27 [project @ 2007-04-05 20:53:40 by jwe]
jwe
parents: 6477
diff changeset
377 along with a warning.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
378
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4466
diff changeset
379 @DOCSTRING(nargout)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
380
12629
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
381 It is good practice at the head of a function to verify that it has been called
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
382 correctly. In Octave the following idiom is seen frequently
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
383
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
384 @example
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
385 @group
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
386 if (nargin < min_#_inputs || nargin > max_#_inputs)
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
387 print_usage ();
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
388 endif
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
389 @end group
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
390 @end example
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
391
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
392 @noindent
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
393 which stops the function execution and prints a message about the correct
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
394 way to call the function whenever the number of inputs is wrong.
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
395
18038
c404cec84eb4 New function validaattributes to perform input checking for functions.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
396 @DOCSTRING(validateattributes)
c404cec84eb4 New function validaattributes to perform input checking for functions.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
397
13852
e36817e2ee60 New function narginchk
Carnë Draug <carandraug+dev@gmail.com>
parents: 13749
diff changeset
398 For compatibility with @sc{matlab}, @code{nargchk}, @code{narginchk} and
e36817e2ee60 New function narginchk
Carnë Draug <carandraug+dev@gmail.com>
parents: 13749
diff changeset
399 @code{nargoutchk} are available which provide similar error checking.
12629
8c25df502846 func.txi: document use of nargin checking at head of function.
Rik <octave@nomad.inbox5.com>
parents: 12592
diff changeset
400
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3294
diff changeset
401 @DOCSTRING(nargchk)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
402
13852
e36817e2ee60 New function narginchk
Carnë Draug <carandraug+dev@gmail.com>
parents: 13749
diff changeset
403 @DOCSTRING(narginchk)
e36817e2ee60 New function narginchk
Carnë Draug <carandraug+dev@gmail.com>
parents: 13749
diff changeset
404
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
405 @DOCSTRING(nargoutchk)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
406
19069
ff820f92cbb5 inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents: 18537
diff changeset
407 There is also the class @code{inputParser} which can perform extremely
ff820f92cbb5 inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents: 18537
diff changeset
408 complex input checking for functions.
ff820f92cbb5 inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents: 18537
diff changeset
409
ff820f92cbb5 inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents: 18537
diff changeset
410 @DOCSTRING(inputParser)
ff820f92cbb5 inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents: 18537
diff changeset
411
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16772
diff changeset
412 @anchor{XREFvarargin} @anchor{XREFvarargout}
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
413 @node Variable-length Argument Lists
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
414 @section Variable-length Argument Lists
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
415 @cindex variable-length argument lists
8567
674d00f5e072 remove variable index
Soren Hauberg <soren@hauberg.org>
parents: 8347
diff changeset
416 @cindex @code{varargin}
8072
3b6e7d04b614 doc fixes
John W. Eaton <jwe@octave.org>
parents: 8015
diff changeset
417
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
418 Sometimes the number of input arguments is not known when the function
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
419 is defined. As an example think of a function that returns the smallest
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
420 of all its input arguments. For example:
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
421
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
422 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
423 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
424 a = smallest (1, 2, 3);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
425 b = smallest (1, 2, 3, 4);
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
426 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
427 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
428
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
429 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
430 In this example both @code{a} and @code{b} would be 1. One way to write
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
431 the @code{smallest} function is
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
432
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
433 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
434 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
435 function val = smallest (arg1, arg2, arg3, arg4, arg5)
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
436 @var{body}
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
437 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
438 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
439 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
440
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
441 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
442 and then use the value of @code{nargin} to determine which of the input
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
443 arguments should be considered. The problem with this approach is
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
444 that it can only handle a limited number of input arguments.
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
445
7588
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
446 If the special parameter name @code{varargin} appears at the end of a
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
447 function parameter list it indicates that the function takes a variable
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
448 number of input arguments. Using @code{varargin} the function
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
449 looks like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
450
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
451 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
452 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
453 function val = smallest (varargin)
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
454 @var{body}
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
455 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
456 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
457 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
458
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
459 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
460 In the function body the input arguments can be accessed through the
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
461 variable @code{varargin}. This variable is a cell array containing
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
462 all the input arguments. @xref{Cell Arrays}, for details on working
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
463 with cell arrays. The @code{smallest} function can now be defined
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
464 like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
465
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
466 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
467 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
468 function val = smallest (varargin)
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
469 val = min ([varargin@{:@}]);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
470 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
471 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
472 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
473
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
474 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
475 This implementation handles any number of input arguments, but it's also
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
476 a very simple solution to the problem.
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
477
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
478 A slightly more complex example of @code{varargin} is a function
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
479 @code{print_arguments} that prints all input arguments. Such a function
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
480 can be defined like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
481
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
482 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
483 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
484 function print_arguments (varargin)
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
485 for i = 1:length (varargin)
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
486 printf ("Input argument %d: ", i);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
487 disp (varargin@{i@});
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
488 endfor
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
489 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
490 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
491 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
492
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
493 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
494 This function produces output like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
495
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
496 @example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
497 @group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
498 print_arguments (1, "two", 3);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
499 @print{} Input argument 1: 1
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
500 @print{} Input argument 2: two
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
501 @print{} Input argument 3: 3
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
502 @end group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
503 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
504
6558
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
505 @DOCSTRING(parseparams)
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
506
10209
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
507 @node Ignoring Arguments
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
508 @section Ignoring Arguments
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
509
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
510 In the formal argument list, it is possible to use the dummy placeholder
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
511 @code{~} instead of a name. This indicates that the corresponding argument
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
512 value should be ignored and not stored to any variable.
10209
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
513
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
514 @example
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
515 @group
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
516 function val = pick2nd (~, arg2)
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
517 val = arg2;
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
518 endfunction
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
519 @end group
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
520 @end example
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
521
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
522 The value of @code{nargin} is not affected by using this declaration.
ea0d83b4470b document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
523
12592
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
524 Return arguments can also be ignored using the same syntax. Functions may
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
525 take advantage of ignored outputs to reduce the number of calculations
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
526 performed. To do so, use the @code{isargout} function to query whether the
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
527 output argument is wanted. For example:
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
528
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
529 @example
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
530 @group
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
531 function [out1, out2] = long_function (x, y, z)
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
532 if (isargout (1))
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
533 ## Long calculation
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
534 @dots{}
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
535 out1 = result;
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
536 endif
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
537 @dots{}
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
538 endfunction
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
539 @end group
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
540 @end example
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
541
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
542 @DOCSTRING(isargout)
732a568bf694 Modify func.txi discussion of output arguments to include discussion of isargout.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
543
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
544 @node Variable-length Return Lists
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
545 @section Variable-length Return Lists
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
546 @cindex variable-length return lists
8567
674d00f5e072 remove variable index
Soren Hauberg <soren@hauberg.org>
parents: 8347
diff changeset
547 @cindex @code{varargout}
8072
3b6e7d04b614 doc fixes
John W. Eaton <jwe@octave.org>
parents: 8015
diff changeset
548
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
549 It is possible to return a variable number of output arguments from a
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
550 function using a syntax that's similar to the one used with the
7588
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
551 special @code{varargin} parameter name. To let a function return a
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
552 variable number of output arguments the special output parameter name
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
553 @code{varargout} is used. As with @code{varargin}, @code{varargout} is
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
554 a cell array that will contain the requested output arguments.
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
555
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
556 As an example the following function sets the first output argument to
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
557 1, the second to 2, and so on.
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
558
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
559 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
560 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
561 function varargout = one_to_n ()
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
562 for i = 1:nargout
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
563 varargout@{i@} = i;
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
564 endfor
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
565 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
566 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
567 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
568
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
569 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
570 When called this function returns values like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
571
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
572 @example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
573 @group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
574 [a, b, c] = one_to_n ()
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
575 @result{} a = 1
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
576 @result{} b = 2
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
577 @result{} c = 3
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
578 @end group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
579 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
580
7588
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
581 If @code{varargin} (@code{varargout}) does not appear as the last
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
582 element of the input (output) parameter list, then it is not special,
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
583 and is handled the same as any other parameter name.
cbedf652a752 doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents: 7031
diff changeset
584
6558
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
585 @DOCSTRING(deal)
e0e1c6df5ab2 [project @ 2007-04-20 19:33:24 by jwe]
jwe
parents: 6556
diff changeset
586
11255
d682cd6669ac Update info-based documentation menus to include new nodes.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
587 @node Returning from a Function
d682cd6669ac Update info-based documentation menus to include new nodes.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
588 @section Returning from a Function
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
589
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
590 The body of a user-defined function can contain a @code{return} statement.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
591 This statement returns control to the rest of the Octave program. It
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
592 looks like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
593
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
594 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
595 return
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
596 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
597
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
598 Unlike the @code{return} statement in C, Octave's @code{return}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
599 statement cannot be used to return a value from a function. Instead,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
600 you must assign values to the list of return variables that are part of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
601 the @code{function} statement. The @code{return} statement simply makes
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
602 it easier to exit a function from a deeply nested loop or conditional
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
603 statement.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
604
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
605 Here is an example of a function that checks to see if any elements of a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
606 vector are nonzero.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
607
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
608 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
609 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
610 function retval = any_nonzero (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
611 retval = 0;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
612 for i = 1:length (v)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
613 if (v (i) != 0)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
614 retval = 1;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
615 return;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
616 endif
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
617 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
618 printf ("no nonzero elements found\n");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
619 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
620 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
621 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
622
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
623 Note that this function could not have been written using the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
624 @code{break} statement to exit the loop once a nonzero value is found
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
625 without adding extra logic to avoid printing the message if the vector
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
626 does contain a nonzero element.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
627
11547
e1851653d59c Eliminate @deffn macros.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
628 @deftypefn {Keyword} {} return
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
629 When Octave encounters the keyword @code{return} inside a function or
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
630 script, it returns control to the caller immediately. At the top level,
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
631 the return statement is ignored. A @code{return} statement is assumed
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
632 at the end of every function definition.
11547
e1851653d59c Eliminate @deffn macros.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
633 @end deftypefn
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
634
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
635 @node Default Arguments
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
636 @section Default Arguments
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
637 @cindex default arguments
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
638
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
639 Since Octave supports variable number of input arguments, it is very useful
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
640 to assign default values to some input arguments. When an input argument
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
641 is declared in the argument list it is possible to assign a default
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
642 value to the argument like this
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
643
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
644 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
645 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
646 function @var{name} (@var{arg1} = @var{val1}, @dots{})
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
647 @var{body}
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
648 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
649 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
650 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
651
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
652 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
653 If no value is assigned to @var{arg1} by the user, it will have the
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
654 value @var{val1}.
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
655
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
656 As an example, the following function implements a variant of the classic
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
657 ``Hello, World'' program.
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
658
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
659 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
660 @group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
661 function hello (who = "World")
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
662 printf ("Hello, %s!\n", who);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
663 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
664 @end group
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
665 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
666
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
667 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
668 When called without an input argument the function prints the following
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
669
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
670 @example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
671 @group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
672 hello ();
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
673 @print{} Hello, World!
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
674 @end group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
675 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
676
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
677 @noindent
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
678 and when it's called with an input argument it prints the following
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
679
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
680 @example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
681 @group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
682 hello ("Beautiful World of Free Software");
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
683 @print{} Hello, Beautiful World of Free Software!
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
684 @end group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
685 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
686
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
687 Sometimes it is useful to explicitly tell Octave to use the default value
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
688 of an input argument. This can be done writing a @samp{:} as the value
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
689 of the input argument when calling the function.
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
690
6510
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
691 @example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
692 @group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
693 hello (:);
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
694 @print{} Hello, World!
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
695 @end group
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
696 @end example
cbae86745c5b [project @ 2007-04-09 23:15:47 by jwe]
jwe
parents: 6502
diff changeset
697
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
698 @node Function Files
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
699 @section Function Files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
700 @cindex function file
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
701
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
702 Except for simple one-shot programs, it is not practical to have to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
703 define all the functions you need each time you need them. Instead, you
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
704 will normally want to save them in a file so that you can easily edit
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
705 them, and save them for use at a later time.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
706
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
707 Octave does not require you to load function definitions from files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
708 before using them. You simply need to put the function definitions in a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
709 place where Octave can find them.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
710
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
711 When Octave encounters an identifier that is undefined, it first looks
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
712 for variables or functions that are already compiled and currently
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
713 listed in its symbol table. If it fails to find a definition there, it
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
714 searches a list of directories (the @dfn{path}) for files ending in
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
715 @file{.m} that have the same base name as the undefined
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
716 identifier.@footnote{The @samp{.m} suffix was chosen for compatibility
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
717 with @sc{matlab}.} Once Octave finds a file with a name that matches,
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
718 the contents of the file are read. If it defines a @emph{single}
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
719 function, it is compiled and executed. @xref{Script Files}, for more
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
720 information about how you can define more than one function in a single
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
721 file.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
722
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
723 When Octave defines a function from a function file, it saves the full
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
724 name of the file it read and the time stamp on the file. If the time
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
725 stamp on the file changes, Octave may reload the file. When Octave is
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
726 running interactively, time stamp checking normally happens at most once
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
727 each time Octave prints the prompt. Searching for new function
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
728 definitions also occurs if the current working directory changes.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
729
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
730 Checking the time stamp allows you to edit the definition of a function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
731 while Octave is running, and automatically use the new function
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
732 definition without having to restart your Octave session.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
733
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
734 To avoid degrading performance unnecessarily by checking the time stamps
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
735 on functions that are not likely to change, Octave assumes that function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
736 files in the directory tree
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
737 @file{@var{octave-home}/share/octave/@var{version}/m}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
738 will not change, so it doesn't have to check their time stamps every time the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
739 functions defined in those files are used. This is normally a very good
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
740 assumption and provides a significant improvement in performance for the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
741 function files that are distributed with Octave.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
742
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
743 If you know that your own function files will not change while you are
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
744 running Octave, you can improve performance by calling
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
745 @code{ignore_function_time_stamp ("all")}, so that Octave will
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
746 ignore the time stamps for all function files. Passing
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17152
diff changeset
747 @qcode{"system"} to this function resets the default behavior.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
748
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5763
diff changeset
749 @c FIXME -- note about time stamps on files in NFS environments?
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
750
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8567
diff changeset
751 @DOCSTRING(edit)
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8567
diff changeset
752
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
753 @DOCSTRING(mfilename)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
754
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
755 @DOCSTRING(ignore_function_time_stamp)
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
756
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
757 @menu
11255
d682cd6669ac Update info-based documentation menus to include new nodes.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
758 * Manipulating the Load Path::
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
759 * Subfunctions::
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
760 * Private Functions::
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
761 * Nested Functions::
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
762 * Overloading and Autoloading::
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
763 * Function Locking::
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
764 * Function Precedence::
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
765 @end menu
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
766
11257
8d4c57258523 fix some menu problems in the manual
John W. Eaton <jwe@octave.org>
parents: 11255
diff changeset
767 @node Manipulating the Load Path
8d4c57258523 fix some menu problems in the manual
John W. Eaton <jwe@octave.org>
parents: 11255
diff changeset
768 @subsection Manipulating the Load Path
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
769
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8817
diff changeset
770 When a function is called, Octave searches a list of directories for
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
771 a file that contains the function declaration. This list of directories
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
772 is known as the load path. By default the load path contains
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
773 a list of directories distributed with Octave plus the current
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
774 working directory. To see your current load path call the @code{path}
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
775 function without any input or output arguments.
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
776
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
777 It is possible to add or remove directories to or from the load path
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
778 using @code{addpath} and @code{rmpath}. As an example, the following
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
779 code adds @samp{~/Octave} to the load path.
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
780
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
781 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14851
diff changeset
782 addpath ("~/Octave")
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
783 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
784
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
785 @noindent
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
786 After this the directory @samp{~/Octave} will be searched for functions.
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
787
6502
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
788 @DOCSTRING(addpath)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
789
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
790 @DOCSTRING(genpath)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
791
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
792 @DOCSTRING(rmpath)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
793
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
794 @DOCSTRING(savepath)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
795
6477
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
796 @DOCSTRING(path)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
797
6502
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
798 @DOCSTRING(pathdef)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
799
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
800 @DOCSTRING(pathsep)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 6501
diff changeset
801
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3402
diff changeset
802 @DOCSTRING(rehash)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3402
diff changeset
803
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3402
diff changeset
804 @DOCSTRING(file_in_loadpath)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3402
diff changeset
805
7638
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7588
diff changeset
806 @DOCSTRING(restoredefaultpath)
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7588
diff changeset
807
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8567
diff changeset
808 @DOCSTRING(command_line_path)
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8567
diff changeset
809
18109
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18104
diff changeset
810 @DOCSTRING(dir_in_loadpath)
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8567
diff changeset
811
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
812 @node Subfunctions
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
813 @subsection Subfunctions
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
814
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
815 A function file may contain secondary functions called
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
816 @dfn{subfunctions}. These secondary functions are only visible to the
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
817 other functions in the same function file. For example, a file
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
818 @file{f.m} containing
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
819
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
820 @example
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
821 @group
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
822 function f ()
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
823 printf ("in f, calling g\n");
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
824 g ()
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
825 endfunction
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
826 function g ()
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
827 printf ("in g, calling h\n");
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
828 h ()
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
829 endfunction
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
830 function h ()
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
831 printf ("in h\n")
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
832 endfunction
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
833 @end group
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
834 @end example
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
835
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
836 @noindent
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
837 defines a main function @code{f} and two subfunctions. The
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
838 subfunctions @code{g} and @code{h} may only be called from the main
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
839 function @code{f} or from the other subfunctions, but not from outside
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
840 the file @file{f.m}.
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
841
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
842 @node Private Functions
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
843 @subsection Private Functions
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
844
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
845 In many cases one function needs to access one or more helper
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
846 functions. If the helper function is limited to the scope of a single
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
847 function, then subfunctions as discussed above might be used. However,
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
848 if a single helper function is used by more than one function, then
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
849 this is no longer possible. In this case the helper functions might
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
850 be placed in a subdirectory, called "private", of the directory in which
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
851 the functions needing access to this helper function are found.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
852
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
853 As a simple example, consider a function @code{func1}, that calls a helper
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
854 function @code{func2} to do much of the work. For example:
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
855
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
856 @example
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
857 @group
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
858 function y = func1 (x)
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
859 y = func2 (x);
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
860 endfunction
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
861 @end group
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
862 @end example
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
863
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
864 @noindent
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
865 Then if the path to @code{func1} is @code{<directory>/func1.m}, and if
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
866 @code{func2} is found in the directory @code{<directory>/private/func2.m},
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
867 then @code{func2} is only available for use of the functions, like
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
868 @code{func1}, that are found in @code{<directory>}.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
869
14851
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
870 @node Nested Functions
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
871 @subsection Nested Functions
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
872
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
873 Nested functions are similar to subfunctions in that only the main function is
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
874 visible outside the file. However, they also allow for child functions to
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
875 access the local variables in their parent function. This shared access mimics
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
876 using a global variable to share information --- but a global variable which is
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
877 not visible to the rest of Octave. As a programming strategy, sharing data
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
878 this way can create code which is difficult to maintain. It is recommended to
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
879 use subfunctions in place of nested functions when possible.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
880
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
881 As a simple example, consider a parent function @code{foo}, that calls a nested
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
882 child function @code{bar}, with a shared variable @var{x}.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
883
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
884 @example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
885 @group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
886 function y = foo ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
887 x = 10;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
888 bar ();
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
889 y = x;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
890
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
891 function bar ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
892 x = 20;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
893 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
894 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
895
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
896 foo ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
897 @result{} 20
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
898 @end group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
899 @end example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
900
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
901 @noindent
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
902 Notice that there is no special syntax for sharing @var{x}. This can lead to
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
903 problems with accidental variable sharing between a parent function and its
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
904 child. While normally variables are inherited, child function parameters and
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
905 return values are local to the child function.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
906
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
907 Now consider the function @code{foobar} that uses variables @var{x} and
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
908 @var{y}. @code{foobar} calls a nested function @code{foo} which takes
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
909 @var{x} as a parameter and returns @var{y}. @code{foo} then calls @code{bat}
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
910 which does some computation.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
911
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
912 @example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
913 @group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
914 function z = foobar ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
915 x = 0;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
916 y = 0;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
917 z = foo (5);
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
918 z += x + y;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
919
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
920 function y = foo (x)
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
921 y = x + bat ();
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
922
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
923 function z = bat ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
924 z = x;
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
925 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
926 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
927 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
928
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
929 foobar ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
930 @result{} 10
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
931 @end group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
932 @end example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
933
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
934 @noindent
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
935 It is important to note that the @var{x} and @var{y} in @code{foobar} remain
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
936 zero, as in @code{foo} they are a return value and parameter respectively. The
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
937 @var{x} in @code{bat} refers to the @var{x} in @code{foo}.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
938
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
939 Variable inheritance leads to a problem for @code{eval} and scripts. If a
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
940 new variable is created in a parent function, it is not clear what should happen
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
941 in nested child functions. For example, consider a parent function @code{foo}
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
942 with a nested child function @code{bar}:
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
943
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
944 @example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
945 @group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
946 function y = foo (to_eval)
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
947 bar ();
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
948 eval (to_eval);
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
949
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
950 function bar ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
951 eval ("x = 100;");
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
952 eval ("y = x;");
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
953 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
954 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
955
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
956 foo ("x = 5;")
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
957 @result{} error: can not add variable "x" to a static workspace
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
958
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
959 foo ("y = 10;")
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
960 @result{} 10
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
961
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
962 foo ("")
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
963 @result{} 100
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
964 @end group
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
965 @end example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
966
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
967 @noindent
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
968 The parent function @code{foo} is unable to create a new variable
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
969 @var{x}, but the child function @code{bar} was successful. Furthermore, even
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
970 in an @code{eval} statement @var{y} in @code{bar} is the same @var{y} as in its
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
971 parent function @code{foo}. The use of @code{eval} in conjunction with nested
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
972 functions is best avoided.
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
973
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
974 As with subfunctions, only the first nested function in a file may be called
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
975 from the outside. Inside a function the rules are more complicated. In
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
976 general a nested function may call:
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
977
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
978 @enumerate 0
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
979 @item
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
980 Globally visible functions
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
981
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
982 @item
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
983 Any function that the nested function's parent can call
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
984
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
985 @item
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
986 Sibling functions (functions that have the same parents)
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
987
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
988 @item
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
989 Direct children
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
990
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
991 @end enumerate
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
992
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
993 As a complex example consider a parent function @code{ex_top} with two
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
994 child functions, @code{ex_a} and @code{ex_b}. In addition, @code{ex_a} has two
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
995 more child functions, @code{ex_aa} and @code{ex_ab}. For example:
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
996
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
997 @example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
998 function ex_top ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
999 ## Can call: ex_top, ex_a, and ex_b
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1000 ## Can NOT call: ex_aa and ex_ab
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1001
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1002 function ex_a ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1003 ## Call call everything
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1004
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1005 function ex_aa ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1006 ## Can call everything
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1007 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1008
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1009 function ex_ab ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1010 ## Can call everything
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1011 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1012 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1013
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1014 function ex_b ()
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1015 ## Can call: ex_top, ex_a, and ex_b
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1016 ## Can NOT call: ex_aa and ex_ab
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1017 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1018 endfunction
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1019 @end example
fa3989fbb1b5 doc: Add subchapter on nested functions (bug #36147)
Max Brister <max@2bass.com>
parents: 14846
diff changeset
1020
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1021 @node Overloading and Autoloading
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1022 @subsection Overloading and Autoloading
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1023
11396
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1024 Functions can be overloaded to work with different input arguments. For
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1025 example, the operator '+' has been overloaded in Octave to work with single,
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1026 double, uint8, int32, and many other arguments. The preferred way to overload
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1027 functions is through classes and object oriented programming
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1028 (@pxref{Function Overloading}). Occasionally, however, one needs to undo
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1029 user overloading and call the default function associated with a specific
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
1030 type. The @code{builtin} function exists for this purpose.
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1031
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1032 @DOCSTRING(builtin)
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1033
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1034 A single dynamically linked file might define several
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1035 functions. However, as Octave searches for functions based on the
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1036 functions filename, Octave needs a manner in which to find each of the
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1037 functions in the dynamically linked file. On operating systems that
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1038 support symbolic links, it is possible to create a symbolic link to the
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1039 original file for each of the functions which it contains.
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1040
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1041 However, there is at least one well known operating system that doesn't
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1042 support symbolic links. Making copies of the original file for each of
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8817
diff changeset
1043 the functions is undesirable as it increases the
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1044 amount of disk space used by Octave. Instead Octave supplies the
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1045 @code{autoload} function, that permits the user to define in which
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1046 file a certain function will be found.
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1047
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1048 @DOCSTRING(autoload)
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1049
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1050 @node Function Locking
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1051 @subsection Function Locking
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1052
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1053 It is sometime desirable to lock a function into memory with the
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1054 @code{mlock} function. This is typically used for dynamically linked
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1055 functions in Oct-files or mex-files that contain some initialization,
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1056 and it is desirable that calling @code{clear} does not remove this
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1057 initialization.
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1058
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1059 As an example,
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1060
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1061 @example
18491
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1062 @group
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1063 function my_function ()
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1064 mlock ();
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1065 @dots{}
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1066 @end group
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1067 @end example
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1068
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1069 @noindent
18491
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1070 prevents @code{my_function} from being removed from memory after it is
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1071 called, even if @code{clear} is called. It is possible to determine if
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1072 a function is locked into memory with the @code{mislocked}, and to unlock
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1073 a function with @code{munlock}, which the following illustrates.
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1074
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1075 @example
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1076 @group
18491
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1077 my_function ();
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1078 mislocked ("my_function")
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1079 @result{} ans = 1
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1080 munlock ("my_function");
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1081 mislocked ("my_function")
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1082 @result{} ans = 0
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1083 @end group
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1084 @end example
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1085
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1086 A common use of @code{mlock} is to prevent persistent variables from
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8817
diff changeset
1087 being removed from memory, as the following example shows:
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1088
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1089 @example
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1090 @group
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14442
diff changeset
1091 function count_calls ()
18491
477b5916cafe doc: Update function locking section with correct usage of mlock (bug #41627)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
1092 mlock ();
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1093 persistent calls = 0;
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7018
diff changeset
1094 printf ("'count_calls' has been called %d times\n",
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7018
diff changeset
1095 ++calls);
6899
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1096 endfunction
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1097
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1098 count_calls ();
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1099 @print{} 'count_calls' has been called 1 times
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1100
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1101 clear count_calls
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1102 count_calls ();
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1103 @print{} 'count_calls' has been called 2 times
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1104 @end group
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1105 @end example
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1106
110c5782fe3b [project @ 2007-09-14 15:17:53 by jwe]
jwe
parents: 6778
diff changeset
1107 @code{mlock} might equally be used to prevent changes to a function from having
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1108 effect in Octave, though a similar effect can be had with the
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1109 @code{ignore_function_time_stamp} function.
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1110
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1111 @DOCSTRING(mlock)
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1112
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1113 @DOCSTRING(munlock)
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1114
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1115 @DOCSTRING(mislocked)
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6570
diff changeset
1116
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1117 @node Function Precedence
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1118 @subsection Function Precedence
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1119
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1120 Given the numerous different ways that Octave can define a function, it
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1121 is possible and even likely that multiple versions of a function, might be
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1122 defined within a particular scope. The precedence of which function will be
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1123 used within a particular scope is given by
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1124
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1125 @enumerate 1
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1126 @item Subfunction
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1127 A subfunction with the required function name in the given scope.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1128
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1129 @item Private function
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1130 A function defined within a private directory of the directory
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1131 which contains the current function.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1132
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1133 @item Class constructor
19074
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 19069
diff changeset
1134 A function that constructs a user class as defined in chapter
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1135 @ref{Object Oriented Programming}.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1136
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1137 @item Class method
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1138 An overloaded function of a class as in chapter
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1139 @ref{Object Oriented Programming}.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1140
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1141 @item Command-line Function
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1142 A function that has been defined on the command-line.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1143
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1144 @item Autoload function
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16772
diff changeset
1145 A function that is marked as autoloaded with @xref{XREFautoload,,autoload}.
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1146
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1147 @item A Function on the Path
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1148 A function that can be found on the users load-path. There can also be
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1149 Oct-file, mex-file or m-file versions of this function and the precedence
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1150 between these versions are in that order.
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1151
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1152 @item Built-in function
18534
f51c1498b9f3 doc: Replace "builtin" with "built-in" for consistency and correctness.
Rik <rik@octave.org>
parents: 18491
diff changeset
1153 A function that is a part of core Octave such as @code{numel}, @code{size},
f51c1498b9f3 doc: Replace "builtin" with "built-in" for consistency and correctness.
Rik <rik@octave.org>
parents: 18491
diff changeset
1154 etc.
8221
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1155 @end enumerate
06094fa570a3 Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents: 8074
diff changeset
1156
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
1157 @node Script Files
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1158 @section Script Files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1159
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1160 A script file is a file containing (almost) any sequence of Octave
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1161 commands. It is read and evaluated just as if you had typed each
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1162 command at the Octave prompt, and provides a convenient way to perform a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1163 sequence of commands that do not logically belong inside a function.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1164
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1165 Unlike a function file, a script file must @emph{not} begin with the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1166 keyword @code{function}. If it does, Octave will assume that it is a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1167 function file, and that it defines a single function that should be
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1168 evaluated as soon as it is defined.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1169
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1170 A script file also differs from a function file in that the variables
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1171 named in a script file are not local variables, but are in the same
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1172 scope as the other variables that are visible on the command line.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1173
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1174 Even though a script file may not begin with the @code{function}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1175 keyword, it is possible to define more than one function in a single
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1176 script file and load (but not execute) all of them at once. To do
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1177 this, the first token in the file (ignoring comments and other white
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1178 space) must be something other than @code{function}. If you have no
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1179 other statements to evaluate, you can use a statement that has no
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1180 effect, like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1181
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1182 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1183 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1184 # Prevent Octave from thinking that this
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1185 # is a function file:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1186
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1187 1;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1188
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1189 # Define function one:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1190
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1191 function one ()
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1192 @dots{}
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1193 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1194 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1195
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1196 To have Octave read and compile these functions into an internal form,
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1197 you need to make sure that the file is in Octave's load path
6477
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
1198 (accessible through the @code{path} function), then simply type the
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
1199 base name of the file that contains the commands. (Octave uses the
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
1200 same rules to search for script files as it does to search for
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
1201 function files.)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1202
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1203 If the first token in a file (ignoring comments) is @code{function},
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1204 Octave will compile the function and try to execute it, printing a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1205 message warning about any non-whitespace characters that appear after
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1206 the function definition.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1207
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1208 Note that Octave does not try to look up the definition of any identifier
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1209 until it needs to evaluate it. This means that Octave will compile the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1210 following statements if they appear in a script file, or are typed at
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1211 the command line,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1212
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1213 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1214 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1215 # not a function file:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1216 1;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1217 function foo ()
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1218 do_something ();
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1219 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1220 function do_something ()
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1221 do_something_else ();
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1222 endfunction
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1223 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1224 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1225
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1226 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1227 even though the function @code{do_something} is not defined before it is
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1228 referenced in the function @code{foo}. This is not an error because
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1229 Octave does not need to resolve all symbols that are referenced by a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1230 function until the function is actually evaluated.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1231
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1232 Since Octave doesn't look for definitions until they are needed, the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1233 following code will always print @samp{bar = 3} whether it is typed
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1234 directly on the command line, read from a script file, or is part of a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1235 function body, even if there is a function or script file called
6477
a441d6681364 [project @ 2007-03-29 13:44:44 by jwe]
jwe
parents: 5775
diff changeset
1236 @file{bar.m} in Octave's path.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1237
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1238 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1239 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1240 eval ("bar = 3");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1241 bar
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1242 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1243 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1244
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1245 Code like this appearing within a function body could fool Octave if
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1246 definitions were resolved as the function was being compiled. It would
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1247 be virtually impossible to make Octave clever enough to evaluate this
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1248 code in a consistent fashion. The parser would have to be able to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1249 perform the call to @code{eval} at compile time, and that would be
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1250 impossible unless all the references in the string to be evaluated could
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1251 also be resolved, and requiring that would be too restrictive (the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1252 string might come from user input, or depend on things that are not
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1253 known until the function is evaluated).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1254
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1255 Although Octave normally executes commands from script files that have
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1256 the name @file{@var{file}.m}, you can use the function @code{source} to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1257 execute commands from any file.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1258
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3294
diff changeset
1259 @DOCSTRING(source)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1260
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
1261 @node Function Handles Anonymous Functions Inline Functions
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
1262 @section Function Handles, Anonymous Functions, Inline Functions
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1263 @cindex handle, function handles
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
1264 @cindex anonymous functions
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1265 @cindex inline, inline functions
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1266
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1267 It can be very convenient store a function in a variable so that it
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1268 can be passed to a different function. For example, a function that
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1269 performs numerical minimization needs access to the function that
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1270 should be minimized.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1271
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1272 @menu
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1273 * Function Handles::
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1274 * Anonymous Functions::
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1275 * Inline Functions::
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1276 @end menu
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1277
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1278 @node Function Handles
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1279 @subsection Function Handles
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1280
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1281 A function handle is a pointer to another function and is defined with
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1282 the syntax
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1283
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1284 @example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1285 @@@var{function-name}
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1286 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1287
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1288 @noindent
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
1289 For example,
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1290
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1291 @example
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
1292 f = @@sin;
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1293 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1294
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1295 @noindent
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
1296 creates a function handle called @code{f} that refers to the
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1297 function @code{sin}.
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1298
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1299 Function handles are used to call other functions indirectly, or to pass
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1300 a function as an argument to another function like @code{quad} or
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
1301 @code{fsolve}. For example:
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1302
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1303 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1304 @group
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
1305 f = @@sin;
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1306 quad (f, 0, pi)
6929
d5bf6be68c87 [project @ 2007-09-28 09:21:40 by dbateman]
dbateman
parents: 6899
diff changeset
1307 @result{} 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1308 @end group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1309 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1310
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1311 You may use @code{feval} to call a function using function handle, or
6570
49f0820425a8 [project @ 2007-04-24 23:06:56 by jwe]
jwe
parents: 6558
diff changeset
1312 simply write the name of the function handle followed by an argument
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1313 list. If there are no arguments, you must use an empty argument list
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
1314 @samp{()}. For example:
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1315
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1316 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1317 @group
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
1318 f = @@sin;
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1319 feval (f, pi/4)
6570
49f0820425a8 [project @ 2007-04-24 23:06:56 by jwe]
jwe
parents: 6558
diff changeset
1320 @result{} 0.70711
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1321 f (pi/4)
6570
49f0820425a8 [project @ 2007-04-24 23:06:56 by jwe]
jwe
parents: 6558
diff changeset
1322 @result{} 0.70711
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1323 @end group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1324 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1325
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1326 @DOCSTRING(is_function_handle)
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1327
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1328 @DOCSTRING(functions)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1329
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1330 @DOCSTRING(func2str)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1331
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1332 @DOCSTRING(str2func)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1333
6570
49f0820425a8 [project @ 2007-04-24 23:06:56 by jwe]
jwe
parents: 6558
diff changeset
1334 @node Anonymous Functions
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1335 @subsection Anonymous Functions
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1336
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1337 Anonymous functions are defined using the syntax
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1338
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1339 @example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1340 @@(@var{argument-list}) @var{expression}
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1341 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1342
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1343 @noindent
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1344 Any variables that are not found in the argument list are inherited from
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1345 the enclosing scope. Anonymous functions are useful for creating simple
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1346 unnamed functions from expressions or for wrapping calls to other
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1347 functions to adapt them for use by functions like @code{quad}. For
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1348 example,
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1349
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1350 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1351 @group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1352 f = @@(x) x.^2;
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1353 quad (f, 0, 10)
6570
49f0820425a8 [project @ 2007-04-24 23:06:56 by jwe]
jwe
parents: 6558
diff changeset
1354 @result{} 333.33
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1355 @end group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1356 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1357
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1358 @noindent
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1359 creates a simple unnamed function from the expression @code{x.^2} and
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1360 passes it to @code{quad},
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1361
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1362 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1363 @group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1364 quad (@@(x) sin (x), 0, pi)
6933
d09b8a5d09e2 [project @ 2007-09-28 10:59:51 by dbateman]
dbateman
parents: 6929
diff changeset
1365 @result{} 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1366 @end group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1367 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1368
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1369 @noindent
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1370 wraps another function, and
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1371
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1372 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1373 @group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1374 a = 1;
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1375 b = 2;
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1376 quad (@@(x) betainc (x, a, b), 0, 0.4)
6929
d5bf6be68c87 [project @ 2007-09-28 09:21:40 by dbateman]
dbateman
parents: 6899
diff changeset
1377 @result{} 0.13867
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
1378 @end group
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1379 @end example
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1380
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1381 @noindent
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1382 adapts a function with several parameters to the form required by
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1383 @code{quad}. In this example, the values of @var{a} and @var{b} that
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1384 are passed to @code{betainc} are inherited from the current
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1385 environment.
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1386
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1387 @node Inline Functions
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1388 @subsection Inline Functions
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1389
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1390 An inline function is created from a string containing the function
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1391 body using the @code{inline} function. The following code defines the
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1392 function @math{f(x) = x^2 + 2}.
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1393
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1394 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14851
diff changeset
1395 f = inline ("x^2 + 2");
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1396 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1397
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1398 @noindent
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1399 After this it is possible to evaluate @math{f} at any @math{x} by
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1400 writing @code{f(x)}.
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1401
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1402 @DOCSTRING(inline)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1403
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1404 @DOCSTRING(argnames)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1405
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1406 @DOCSTRING(formula)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4718
diff changeset
1407
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
1408 @DOCSTRING(symvar)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
1409
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1410 @node Commands
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1411 @section Commands
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1412
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1413 Commands are a special class of functions that only accept string
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1414 input arguments. A command can be called as an ordinary function, but
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1415 it can also be called without the parentheses. For example,
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1416
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1417 @example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1418 my_command hello world
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1419 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1420
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1421 @noindent
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1422 is equivalent to
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1423
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1424 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14851
diff changeset
1425 my_command ("hello", "world")
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1426 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1427
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1428 @noindent
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1429 The general form of a command call is
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1430
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1431 @example
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1432 @var{cmdname} @var{arg1} @var{arg2} @dots{}
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1433 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1434
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1435 @noindent
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1436 which translates directly to
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1437
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1438 @example
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1439 @var{cmdname} ("@var{arg1}", "@var{arg2}", @dots{})
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1440 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1441
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1442 Any regular function can be used as a command if it accepts string input
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1443 arguments. For example:
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
1444
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1445 @example
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1446 @group
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1447 toupper lower_case_arg
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1448 @result{} ans = LOWER_CASE_ARG
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1449 @end group
6638
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1450 @end example
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1451
15837c5982cb [project @ 2007-05-21 19:24:19 by jwe]
jwe
parents: 6635
diff changeset
1452 One difficulty of commands occurs when one of the string input arguments
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1453 is stored in a variable. Because Octave can't tell the difference between
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1454 a variable name and an ordinary string, it is not possible to pass a
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
1455 variable as input to a command. In such a situation a command must be
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1456 called as a function. For example:
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1457
11392
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1458 @example
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1459 @group
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1460 strvar = "hello world";
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1461 toupper strvar
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1462 @result{} ans = STRVAR
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1463 toupper (strvar)
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1464 @result{} ans = HELLO WORLD
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1465 @end group
757efa1d7e2a Remove deprecated functions from manual.
Rik <octave@nomad.inbox5.com>
parents: 11257
diff changeset
1466 @end example
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1467
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6510
diff changeset
1468
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
1469 @node Organization of Functions
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1470 @section Organization of Functions Distributed with Octave
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1471
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1472 Many of Octave's standard functions are distributed as function files.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1473 They are loosely organized by topic, in subdirectories of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1474 @file{@var{octave-home}/lib/octave/@var{version}/m}, to make it easier
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1475 to find them.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1476
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1477 The following is a list of all the function file subdirectories, and the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1478 types of functions you will find there.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1479
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1480 @table @file
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1481 @item audio
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1482 Functions for playing and recording sounds.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1483
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1484 @item deprecated
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1485 Out-of-date functions which will eventually be removed from Octave.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1486
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1487 @item elfun
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1488 Elementary functions, principally trigonometric.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1489
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1490 @item @@ftp
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1491 Class functions for the FTP object.
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1492
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1493 @item general
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1494 Miscellaneous matrix manipulations, like @code{flipud}, @code{rot90},
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1495 and @code{triu}, as well as other basic functions, like
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3760
diff changeset
1496 @code{ismatrix}, @code{nargchk}, etc.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1497
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1498 @item geometry
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1499 Functions related to Delaunay triangulation.
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1500
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1501 @item help
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1502 Functions for Octave's built-in help system.
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1503
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1504 @item image
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1505 Image processing tools. These functions require the X Window System.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1506
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1507 @item io
8325
b93ac0586e4b spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents: 8286
diff changeset
1508 Input-output functions.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1509
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1510 @item linear-algebra
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1511 Functions for linear algebra.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1512
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1513 @item miscellaneous
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1514 Functions that don't really belong anywhere else.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1515
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1516 @item optimization
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12632
diff changeset
1517 Functions related to minimization, optimization, and root finding.
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1518
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1519 @item path
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1520 Functions to manage the directory path Octave uses to find functions.
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1521
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1522 @item pkg
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1523 Package manager for installing external packages of functions in Octave.
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1524
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1525 @item plot
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6554
diff changeset
1526 Functions for displaying and printing two- and three-dimensional graphs.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1527
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1528 @item polynomial
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1529 Functions for manipulating polynomials.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1530
14133
b25559bd5aaa doc: Document prefs directory in list of installed script files.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
1531 @item prefs
b25559bd5aaa doc: Document prefs directory in list of installed script files.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
1532 Functions implementing user-defined preferences.
b25559bd5aaa doc: Document prefs directory in list of installed script files.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
1533
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1534 @item set
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1535 Functions for creating and manipulating sets of unique values.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1536
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1537 @item signal
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1538 Functions for signal processing applications.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1539
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1540 @item sparse
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1541 Functions for handling sparse matrices.
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1542
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1543 @item specfun
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1544 Special functions such as @code{bessel} or @code{factor}.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1545
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1546 @item special-matrix
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1547 Functions that create special matrix forms such as Hilbert or Vandermonde
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1548 matrices.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1549
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1550 @item startup
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1551 Octave's system-wide startup file.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1552
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1553 @item statistics
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1554 Statistical functions.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1555
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1556 @item strings
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1557 Miscellaneous string-handling functions.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1558
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1559 @item testfun
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1560 Functions for performing unit tests on other functions.
6554
5dde4dc2bcaf [project @ 2007-04-20 17:16:50 by jwe]
jwe
parents: 6549
diff changeset
1561
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1562 @item time
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12629
diff changeset
1563 Functions related to time and date processing.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
1564 @end table