annotate doc/interpreter/tips.txi @ 10812:5b68000faac1

tips update
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 21 Jul 2010 09:01:06 +0200
parents 3140cb7a05a1
children 322f43e0e170
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
1 @c Copyright (C) 1996, 1997, 1999, 2002, 2004, 2005, 2007, 2008,
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2 @c 2009 John W. Eaton
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
3 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
4 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
5 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
6 @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: 7017
diff changeset
7 @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: 7017
diff changeset
8 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
9 @c your option) any later version.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
10 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
11 @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: 7017
diff changeset
12 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
13 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
14 @c for more details.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
15 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
16 @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: 7017
diff changeset
17 @c along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7017
diff changeset
18 @c <http://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
19
9032
349616d9c38e Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
20 @node Tips and Standards
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
21 @appendix Tips and Standards
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
22 @cindex tips
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
23 @cindex standards of coding style
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
24 @cindex coding standards
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 This chapter describes no additional features of Octave. Instead it
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
27 gives advice on making effective use of the features described in the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
28 previous chapters.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
29
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
30 @menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
31 * Style Tips:: Writing clean and robust programs.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
32 * Coding Tips:: Making code run faster.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
33 * Comment Tips:: Conventions for writing comments.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
34 * Function Headers:: Standard headers for functions.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
35 * Documentation Tips:: Writing readable documentation strings.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
36 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
37
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
38 @node Style Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
39 @section Writing Clean Octave Programs
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
40
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
41 Here are some tips for avoiding common errors in writing Octave code
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
42 intended for widespread use:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
43
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
44 @itemize @bullet
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
45 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
46 Since all global variables share the same name space, and all functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
47 share another name space, you should choose a short word to distinguish
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
48 your program from other Octave programs. Then take care to begin the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
49 names of all global variables, constants, and functions with the chosen
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
50 prefix. This helps avoid name conflicts.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
51
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
52 If you write a function that you think ought to be added to Octave under
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
53 a certain name, such as @code{fiddle_matrix}, don't call it by that name
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
54 in your program. Call it @code{mylib_fiddle_matrix} in your program,
5041
b2ce28713791 [project @ 2004-10-01 18:12:10 by jwe]
jwe
parents: 4167
diff changeset
55 and send mail to @email{maintainers@@octave.org} suggesting that it
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
56 be added to Octave. If and when it is, the name can be changed easily
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
57 enough.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
58
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
59 If one prefix is insufficient, your package may use two or three
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
60 alternative common prefixes, so long as they make sense.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
61
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
62 Separate the prefix from the rest of the symbol name with an underscore
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
63 @samp{_}. This will be consistent with Octave itself and with most
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
64 Octave programs.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
65
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
66 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
67 When you encounter an error condition, call the function @code{error}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
68 (or @code{usage}). The @code{error} and @code{usage} functions do not
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
69 return.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
70 @xref{Errors}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
71
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
72 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
73 Please put a copyright notice on the file if you give copies to anyone.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
74 Use the same lines that appear at the top of the function files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
75 distributed with Octave. If you have not signed papers to assign the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
76 copyright to anyone else, then place your name in the copyright notice.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
77 @end itemize
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
78
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
79 @node Coding Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
80 @section Tips for Making Code Run Faster.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
81 @cindex execution speed
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
82 @cindex speedups
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
83
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
84 Here are some ways of improving the execution speed of Octave programs.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
85
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
86 @itemize @bullet
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
87 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
88 Vectorize loops. For instance, rather than
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
89 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
90 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
91 for i = 1:n-1
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
92 a(i) = b(i+1) - b(i);
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
93 endfor
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
94 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
95 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
96
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
97 write
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
98
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
99 @example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
100 a = b(2:n) - b(1:n-1);
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
101 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
102
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
103 This is especially important for loops with "cheap" bodies. Often it suffices to vectorize
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
104 just the innermost loop to get acceptable performance. A general rule of thumb is that the
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
105 "order" of the vectorized body should be greater or equal to the "order" of the enclosing loop.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
106
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
107 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
108 Use built-in and library functions if possible. Built-in and compiled functions are very fast.
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
109 Even with a m-file library function, chances are good that it is already optimized, or will be
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
110 optimized more in a future release.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
111
10812
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
112 For instance, even better than
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
113
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
114 @example
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
115 a = b(2:n) - b(1:n-1);
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
116 @end example
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
117
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
118 is
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
119
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
120 @example
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
121 a = diff (b);
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
122 @end example
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
123
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
124
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
125 @item
10812
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
126 Avoid computing costly intermediate results multiple times. Octave currently
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
127 does not eliminate common subexpressions.
9486
d85a43495faa update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9356
diff changeset
128 Also, certain internal computation results are cached for variables.
d85a43495faa update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9356
diff changeset
129 For instance, if a matrix variable is used multiple times as an index,
d85a43495faa update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9356
diff changeset
130 checking the indices (and internal conversion to integers) is only done once.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
131
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
132 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
133 Be aware of lazy copies (copy-on-write). When a copy of an object
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
134 is created, the data is not immediately copied, but rather shared. The actual
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
135 copying is postponed until the copied data needs to be modified. For example:
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
136
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
137 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
138 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
139 a = zeros (1000); # create a 1000x1000 matrix
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
140 b = a; # no copying done here
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
141 b(1) = 1; # copying done here
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
142 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
143 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
144
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
145 Lazy copying applies to whole Octave objects such as matrices, cells, struct,
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
146 and also individual cell or struct elements (not array elements).
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
147
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
148 Additionally, index expressions also use lazy copying when Octave can determine
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
149 that the indexed portion is contiguous in memory. For example:
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
150
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
151 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
152 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
153 a = zeros (1000); # create a 1000x1000 matrix
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
154 b = a(:,10:100); # no copying done here
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
155 b = a(10:100,:); # copying done here
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
156 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
157 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
158
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
159 This applies to arrays (matrices), cell arrays, and structs indexed using ().
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
160 Index expressions generating cs-lists can also benefit of shallow copying
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
161 in some cases. In particular, when @var{a} is a struct array, expressions like
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
162 @code{@{a.x@}, @{a(:,2).x@}} will use lazy copying, so that data can be shared
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
163 between a struct array and a cell array.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
164
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
165 Most indexing expressions do not live longer than their `parent' objects.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
166 In rare cases, however, a lazily copied slice outlasts its parent, in which
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
167 case it becomes orphaned, still occupying unnecessarily more memory than needed.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
168 To provide a remedy working in most real cases,
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
169 Octave checks for orphaned lazy slices at certain situations, when a value
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
170 is stored into a "permanent" location, such as a named variable or cell or
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
171 struct element, and possibly economizes them. For example
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
172
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
173 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
174 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
175 a = zeros (1000); # create a 1000x1000 matrix
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
176 b = a(:,10:100); # lazy slice
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
177 a = []; # the original a array is still allocated
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
178 c@{1@} = b; # b is reallocated at this point
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
179 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
180 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
181
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
182 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
183 Avoid deep recursion. Function calls to m-file functions carry a relatively significant overhead,
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
184 so rewriting a recursion as a loop often helps. Also, note that the maximum level of recursion is
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
185 limited.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
186
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
187 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
188 Avoid resizing matrices unnecessarily. When building a single result
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
189 matrix from a series of calculations, set the size of the result matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
190 first, then insert values into it. Write
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
191
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
192 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
193 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
194 result = zeros (big_n, big_m)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
195 for i = over:and_over
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
196 r1 = @dots{}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
197 r2 = @dots{}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
198 result (r1, r2) = new_value ();
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
199 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
200 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
201 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
202
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
203 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
204 instead of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
205
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
206 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
207 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
208 result = [];
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
209 for i = ever:and_ever
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
210 result = [ result, new_value() ];
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
211 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
212 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
213 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
214
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
215 Sometimes the number of items can't be computed in advance, and stack-like operations
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
216 are needed. When elements are being repeatedly inserted at/removed from the end of an
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
217 array, Octave detects it as stack usage and attempts to use a smarter memory management
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10284
diff changeset
218 strategy pre-allocating the array in bigger chunks. Likewise works for cell and
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
219 struct arrays.
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
220
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
221 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
222 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
223 a = [];
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
224 while (condition)
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
225 @dots{}
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
226 a(end+1) = value; # "push" operation
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
227 @dots{}
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
228 a(end) = []; # "pop" operation
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
229 @dots{}
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
230 endwhile
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
231 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
232 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
233
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
234 @item
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
235 Use @code{cellfun} intelligently. The @code{cellfun} function is a useful tool
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
236 for avoiding loops. @xref{Processing Data in Cell Arrays}.
10284
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
237 @code{cellfun} is often used with anonymous function handles; however, calling
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
238 an anonymous function involves an overhead quite comparable to the overhead
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
239 of an m-file function. Passing a handle to a built-in function is faster,
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
240 because the interpreter is not involved in the internal loop. For example:
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
241
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
242 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
243 @group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
244 a = @{@dots{}@}
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
245 v = cellfun (@@(x) det(x), a); # compute determinants
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
246 v = cellfun (@@det, a); # faster
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9486
diff changeset
247 @end group
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
248 @end example
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
249
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
250 @item
10284
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
251 Octave includes a number of other functions that can replace common types of loops,
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
252 including @code{bsxfun}, @code{arrayfun}, @code{structfun}, @code{accumarray}.
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
253 These functions can take an arbitrary function as a handle.
10812
5b68000faac1 tips update
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
254 Be sure to get familiar with them if you want to become an Octave expert.
10284
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
255
c3df189b1b15 more coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
256 @item
9356
b2133f97079d update coding tips
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
257 Avoid calling @code{eval} or @code{feval} excessively, because
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
258 they require Octave to parse input or look up the name of a function in
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
259 the symbol table.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
260
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
261 If you are using @code{eval} as an exception handling mechanism and not
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
262 because you need to execute some arbitrary text, use the @code{try}
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 9032
diff changeset
263 statement instead. @xref{The @code{try} Statement}.
3294
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 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
266 If you are calling lots of functions but none of them will need to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
267 change during your run, set the variable
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
268 @code{ignore_function_time_stamp} to @code{"all"} so that Octave doesn't
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
269 waste a lot of time checking to see if you have updated your function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
270 files.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
271 @end itemize
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
272
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
273 @node Comment Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
274 @section Tips on Writing Comments
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
275
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
276 Here are the conventions to follow when writing comments.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
277
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
278 @table @samp
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
279 @item #
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
280 Comments that start with a single sharp-sign, @samp{#}, should all be
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
281 aligned to the same column on the right of the source code. Such
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
282 comments usually explain how the code on the same line does its job. In
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
283 the Emacs mode for Octave, the @kbd{M-;} (@code{indent-for-comment})
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
284 command automatically inserts such a @samp{#} in the right place, or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
285 aligns such a comment if it is already present.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
286
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
287 @item ##
7345
74075b3b54c1 [project @ 2008-01-04 18:42:40 by jwe]
jwe
parents: 7081
diff changeset
288 Comments that start with a double sharp-sign, @samp{##}, should be aligned to
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
289 the same level of indentation as the code. Such comments usually
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
290 describe the purpose of the following lines or the state of the program
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
291 at that point.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
292 @end table
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 The indentation commands of the Octave mode in Emacs, such as @kbd{M-;}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
296 (@code{indent-for-comment}) and @kbd{TAB} (@code{octave-indent-line})
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
297 automatically indent comments according to these conventions,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
298 depending on the number of semicolons. @xref{Comments,,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
299 Manipulating Comments, emacs, The GNU Emacs Manual}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
300
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
301 @node Function Headers
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
302 @section Conventional Headers for Octave Functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
303 @cindex header comments
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 Octave has conventions for using special comments in function files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
306 to give information such as who wrote them. This section explains these
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
307 conventions.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
308
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
309 The top of the file should contain a copyright notice, followed by a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
310 block of comments that can be used as the help text for the function.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
311 Here is an example:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
312
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
313 @example
6778
083721ae3dfa [project @ 2007-07-18 17:03:10 by jwe]
jwe
parents: 6670
diff changeset
314 ## Copyright (C) 1996, 1997, 2007 John W. Eaton
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
315 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
316 ## This file is part of Octave.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
317 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
318 ## Octave is free software; you can redistribute it and/or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
319 ## modify it under the terms of the GNU General Public
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
320 ## License as published by the Free Software Foundation;
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
321 ## either version 3 of the License, or (at your option) any
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
322 ## later version.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
323 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
324 ## Octave is distributed in the hope that it will be useful,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
325 ## but WITHOUT ANY WARRANTY; without even the implied
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
326 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
327 ## PURPOSE. See the GNU General Public License for more
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
328 ## details.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
329 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
330 ## You should have received a copy of the GNU General Public
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
331 ## License along with Octave; see the file COPYING. If not,
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
332 ## see <http://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
333
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
334 ## usage: [IN, OUT, PID] = popen2 (COMMAND, ARGS)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
335 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
336 ## Start a subprocess with two-way communication. COMMAND
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
337 ## specifies the name of the command to start. ARGS is an
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
338 ## array of strings containing options for COMMAND. IN and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
339 ## OUT are the file ids of the input and streams for the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
340 ## subprocess, and PID is the process id of the subprocess,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
341 ## or -1 if COMMAND could not be executed.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
342 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
343 ## Example:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
344 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
345 ## [in, out, pid] = popen2 ("sort", "-nr");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
346 ## fputs (in, "these\nare\nsome\nstrings\n");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
347 ## fclose (in);
7768
a2d9f325b65a Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents: 7345
diff changeset
348 ## while (ischar (s = fgets (out)))
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
349 ## fputs (stdout, s);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
350 ## endwhile
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
351 ## fclose (out);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
352 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
353
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
354 Octave uses the first block of comments in a function file that do not
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
355 appear to be a copyright notice as the help text for the file. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
356 Octave to recognize the first comment block as a copyright notice, it
6530
f80cc454860d [project @ 2007-04-16 23:16:58 by jwe]
jwe
parents: 5307
diff changeset
357 must start with the word `Copyright' after stripping the leading
f80cc454860d [project @ 2007-04-16 23:16:58 by jwe]
jwe
parents: 5307
diff changeset
358 comment characters.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
359
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
360 After the copyright notice and help text come several @dfn{header
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
361 comment} lines, each beginning with @samp{## @var{header-name}:}. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
362 example,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
363
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
364 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
365 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
366 ## Author: jwe
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
367 ## Keywords: subprocesses input-output
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
368 ## Maintainer: jwe
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
369 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
370 @end example
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 Here is a table of the conventional possibilities for @var{header-name}:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
373
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
374 @table @samp
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
375 @item Author
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
376 This line states the name and net address of at least the principal
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
377 author of the library.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
378
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6576
diff changeset
379 @example
9322
66fdc831c580 fix jwe email address
John W. Eaton <jwe@octave.org>
parents: 9210
diff changeset
380 ## Author: John W. Eaton <jwe@@octave.org>
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6576
diff changeset
381 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
382
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
383 @item Maintainer
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
384 This line should contain a single name/address as in the Author line, or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
385 an address only, or the string @samp{jwe}. If there is no maintainer
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
386 line, the person(s) in the Author field are presumed to be the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
387 maintainers. The example above is mildly bogus because the maintainer
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
388 line is redundant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
389
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
390 The idea behind the @samp{Author} and @samp{Maintainer} lines is to make
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
391 possible a function to ``send mail to the maintainer'' without
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
392 having to mine the name out by hand.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
393
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
394 Be sure to surround the network address with @samp{<@dots{}>} if
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
395 you include the person's full name as well as the network address.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
396
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
397 @item Created
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
398 This optional line gives the original creation date of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
399 file. For historical interest only.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
400
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
401 @item Version
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
402 If you wish to record version numbers for the individual Octave program,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
403 put them in this line.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
404
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
405 @item Adapted-By
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
406 In this header line, place the name of the person who adapted the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
407 library for installation (to make it fit the style conventions, for
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
408 example).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
409
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
410 @item Keywords
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
411 This line lists keywords. Eventually, it will be used by an apropos
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
412 command to allow people will find your package when they're looking for
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
413 things by topic area. To separate the keywords, you can use spaces,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
414 commas, or both.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
415 @end table
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
416
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
417 Just about every Octave function ought to have the @samp{Author} and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
418 @samp{Keywords} header comment lines. Use the others if they are
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
419 appropriate. You can also put in header lines with other header
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
420 names---they have no standard meanings, so they can't do any harm.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
421
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
422 @node Documentation Tips
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
423 @section Tips for Documentation Strings
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
424
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
425 As noted above, documentation is typically in a commented header block
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
426 on an Octave function following the copyright statement. The help string
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6778
diff changeset
427 shown above is an unformatted string and will be displayed as is by
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
428 Octave. Here are some tips for the writing of documentation strings.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
429
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
430 @itemize @bullet
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
431 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
432 Every command, function, or variable intended for users to know about
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
433 should have a documentation string.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
434
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
435 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
436 An internal variable or subroutine of an Octave program might as well have
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
437 a documentation string.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
438
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
439 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
440 The first line of the documentation string should consist of one or two
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
441 complete sentences that stand on their own as a summary.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
442
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
443 The documentation string can have additional lines that expand on the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
444 details of how to use the function or variable. The additional lines
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
445 should also be made up of complete sentences.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
446
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
447 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
448 For consistency, phrase the verb in the first sentence of a
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
449 documentation string as an infinitive with ``to'' omitted. For
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
450 instance, use ``Return the frob of A and B.'' in preference to ``Returns
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
451 the frob of A and B@.'' Usually it looks good to do likewise for the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
452 rest of the first paragraph. Subsequent paragraphs usually look better
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
453 if they have proper subjects.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
454
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
455 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
456 Write documentation strings in the active voice, not the passive, and in
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
457 the present tense, not the future. For instance, use ``Return a list
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
458 containing A and B.'' instead of ``A list containing A and B will be
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
459 returned.''
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
460
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
461 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
462 Avoid using the word ``cause'' (or its equivalents) unnecessarily.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
463 Instead of, ``Cause Octave to display text in boldface,'' write just
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
464 ``Display text in boldface.''
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
465
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
466 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
467 Do not start or end a documentation string with whitespace.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
468
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
469 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
470 Format the documentation string so that it fits in an Emacs window on an
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
471 80-column screen. It is a good idea for most lines to be no wider than
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
472 60 characters.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
473
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
474 However, rather than simply filling the entire documentation string, you
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
475 can make it much more readable by choosing line breaks with care.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
476 Use blank lines between topics if the documentation string is long.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
477
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
478 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
479 @strong{Do not} indent subsequent lines of a documentation string so
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
480 that the text is lined up in the source code with the text of the first
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
481 line. This looks nice in the source code, but looks bizarre when users
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
482 view the documentation. Remember that the indentation before the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
483 starting double-quote is not part of the string!
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
484
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
485 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
486 The documentation string for a variable that is a yes-or-no flag should
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
487 start with words such as ``Nonzero means@dots{}'', to make it clear that
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
488 all nonzero values are equivalent and indicate explicitly what zero and
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
489 nonzero mean.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
490
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
491 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
492 When a function's documentation string mentions the value of an argument
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
493 of the function, use the argument name in capital letters as if it were
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
494 a name for that value. Thus, the documentation string of the operator
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
495 @code{/} refers to its second argument as @samp{DIVISOR}, because the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
496 actual argument name is @code{divisor}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
497
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
498 Also use all caps for meta-syntactic variables, such as when you show
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
499 the decomposition of a list or vector into subunits, some of which may
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
500 vary.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
501 @end itemize
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
502
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
503 Octave also allows extensive formatting of the help string of functions
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
504 using Texinfo. The effect on the online documentation is relatively
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
505 small, but makes the help string of functions conform to the help of
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
506 Octave's own functions. However, the effect on the appearance of printed
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
507 or online documentation will be greatly improved.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
508
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
509 The fundamental building block of Texinfo documentation strings is the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
510 Texinfo-macro @code{@@deftypefn}, which takes three arguments: The class
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
511 the function is in, its output arguments, and the function's
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
512 signature. Typical classes for functions include @code{Function File}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
513 for standard Octave functions, and @code{Loadable Function} for
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
514 dynamically linked functions. A skeletal Texinfo documentation string
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
515 therefore looks like this
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
516
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
517 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
518 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
519 -*- texinfo -*-
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
520 @@deftypefn@{Function File@} @{@@var@{ret@} =@} fn (@dots{})
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
521 @@cindex index term
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
522 Help text in Texinfo format. Code samples should be marked
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
523 like @@code@{sample of code@} and variables should be marked
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
524 as @@var@{variable@}.
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
525 @@seealso@{fn2@}
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
526 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
527 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
528 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
529
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
530 This help string must be commented in user functions, or in the help
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9080
diff changeset
531 string of the @w{@code{DEFUN_DLD}} macro for dynamically loadable
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
532 functions. The important aspects of the documentation string are
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
533
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
534 @table @asis
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10284
diff changeset
535 @item -*- @nospell{texinfo} -*-
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 7768
diff changeset
536 This string signals Octave that the following text is in Texinfo format,
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
537 and should be the first part of any help string in Texinfo format.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
538 @item @@deftypefn@{class@} @dots{} @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
539 The entire help string should be enclosed within the block defined by
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
540 deftypefn.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
541 @item @@cindex index term
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
542 This generates an index entry, and can be useful when the function is
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
543 included as part of a larger piece of documentation. It is ignored
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
544 within Octave's help viewer. Only one index term may appear per line
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
545 but multiple @@cindex lines are valid if the function should be
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
546 filed under different terms.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
547 @item @@var@{variable@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
548 All variables should be marked with this macro. The markup of variables
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
549 is then changed appropriately for display.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
550 @item @@code@{sample of code@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
551 All samples of code should be marked with this macro for the same
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
552 reasons as the @@var macro.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
553 @item @@seealso@{function2@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
554 This is a comma separated list of function names that allows cross
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
555 referencing from one function documentation string to another.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
556 @end table
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
557
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
558 Texinfo format has been designed to generate output for online viewing
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
559 with text terminals as well as generating high-quality printed output.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
560 To these ends, Texinfo has commands which control the diversion of parts
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
561 of the document into a particular output processor. Three formats are
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10284
diff changeset
562 of importance: info, HTML and @TeX{}. These are selected with
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
563
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
564 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
565 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
566 @@ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
567 Text area for info only
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
568 @@end ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
569 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
570 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
571
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
572 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
573 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
574 @@ifhtml
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
575 Text area for HTML only
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
576 @@end ifhtml
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
577 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
578 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
579
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
580 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
581 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
582 @@tex
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
583 Text area for TeX only
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
584 @@end tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
585 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
586 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
587
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10284
diff changeset
588 Note that often @TeX{} output can be used in HTML documents and so often
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
589 the @code{@@ifhtml} blocks are unnecessary. If no specific output
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
590 processor is chosen, by default, the text goes into all output
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
591 processors. It is usual to have the above blocks in pairs to allow the
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
592 same information to be conveyed in all output formats, but with a
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
593 different markup. Currently, most Octave documentation only makes a
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
594 distinction between @TeX{} and all other formats. Therefore, the
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
595 following construct is seen repeatedly.
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
596
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
597 @example
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
598 @group
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
599 @@tex
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
600 text for TeX only
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
601 @@end tex
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
602 @@ifnottex
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
603 text for info, HTML, plaintext
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
604 @@end ifnottex
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
605 @end group
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
606 @end example
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
607
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
608 Another important feature of Texinfo that is often used in Octave help
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
609 strings is the @code{@@example} environment. An example of its use is
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
610
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
611 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
612 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
613 @@example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
614 @@group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
615 @@code@{2 * 2@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
616 @@result@{@} 4
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
617 @@end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
618 @@end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
619 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
620 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
621
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
622 which produces
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
623
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
624 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
625 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
626 @code{2 * 2}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
627 @result{} 4
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
628 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
629 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
630
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
631 The @code{@@group} block prevents the example from being split across a
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
632 page boundary, while the @code{@@result@{@}} macro produces a right
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
633 arrow signifying the result of a command. If your example is larger than
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
634 20 lines it is better NOT to use grouping so that a reasonable page boundary
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
635 can be calculated.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
636
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8347
diff changeset
637 In many cases a function has multiple ways in which it can be called,
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
638 and the @code{@@deftypefnx} macro can be used to give alternatives. For
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
639 example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
640
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
641 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
642 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
643 -*- texinfo -*-
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
644 @@deftypefn@{Function File@} @{@@var@{a@} =@} fn (@@var@{x@}, @dots{})
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
645 @@deftypefnx@{Function File@} @{@@var@{a@} =@} fn (@@var@{y@}, @dots{})
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
646 Help text in Texinfo format.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
647 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
648 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
649 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
650
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
651 Many complete examples of Texinfo documentation can be taken from the
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
652 help strings for the Octave functions themselves. A relatively complete
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
653 example of which is the @code{nchoosek} function. The Texinfo
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
654 documentation string for @code{nchoosek} is
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
655
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
656 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
657 -*- texinfo -*-
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
658 @@deftypefn @{Function File@} @{@} nchoosek (@@var@{n@}, @@var@{k@})
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
659
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
660 Compute the binomial coefficient or all combinations of
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
661 @@var@{n@}. If @@var@{n@} is a scalar then, calculate the
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
662 binomial coefficient of @@var@{n@} and @@var@{k@}, defined as
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
663
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
664 @@tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
665 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
666 @{n \choose k@} = @{n (n-1) (n-2) \cdots (n-k+1) \over k!@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
667 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
668 @@end tex
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
669 @@ifnottex
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
670
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
671 @@example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
672 @@group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
673 / \
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
674 | n | n (n-1) (n-2) @dots{} (n-k+1)
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
675 | | = -------------------------
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
676 | k | k!
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
677 \ /
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
678 @@end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
679 @@end example
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
680 @@end ifnottex
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
681
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
682 If @@var@{n@} is a vector, this generates all combinations
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
683 of the elements of @@var@{n@}, taken @@var@{k@} at a time,
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
684 one row per combination. The resulting @@var@{c@} has size
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
685 @@code@{[nchoosek (length (@@var@{n@}),@@var@{k@}), @@var@{k@}]@}.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
686
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
687 @@code@{nchoosek@} works only for non-negative integer arguments; use
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
688 @@code@{bincoeff@} for non-integer scalar arguments and for using vector
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
689 arguments to compute many coefficients at once.
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
690
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
691 @@seealso@{bincoeff@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
692 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
693 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
694
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
695 which demonstrates most of the concepts discussed above.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
696 @iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
697 This documentation string renders as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
698
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
699 @c Note actually use the output of info below rather than try and
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
700 @c reproduce it here to prevent it looking different than how it would
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
701 @c appear with info.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
702 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
703 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
704 -- Function File: C = nchoosek (N, K)
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
705 Compute the binomial coefficient or all combinations
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
706 of N. If N is a scalar then, calculate the binomial
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
707 coefficient of N and K, defined as
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
708
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
709 / \
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
710 | n | n (n-1) (n-2) @dots{} (n-k+1) n!
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
711 | | = ------------------------- = ---------
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
712 | k | k! k! (n-k)!
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
713 \ /
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
714
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
715 If N is a vector generate all combinations of the
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
716 elements of N, taken K at a time, one row per
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
717 combination. The resulting C has size `[nchoosek
7081
503001863427 [project @ 2007-10-31 01:08:14 by jwe]
jwe
parents: 7018
diff changeset
718 (length (N), K), K]'.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
719
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
720 `nchoosek' works only for non-negative integer
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
721 arguments; use `bincoeff' for non-integer scalar
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
722 arguments and for using vector arguments to compute
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
723 many coefficients at once.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
724
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
725 See also: bincoeff.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
726 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
727 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
728
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9080
diff changeset
729 using info, whereas in a printed documentation using @TeX{} it will appear
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
730 as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
731
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
732 @deftypefn {Function File} {@var{c} =} nchoosek (@var{n}, @var{k})
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
733
6576
f14a0d35f90b [project @ 2007-04-25 14:22:34 by jwe]
jwe
parents: 6574
diff changeset
734 Compute the binomial coefficient or all combinations of @var{n}.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
735 If @var{n} is a scalar then, calculate the binomial coefficient
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
736 of @var{n} and @var{k}, defined as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
737
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
738 @tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
739 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
740 {n \choose k} = {n (n-1) (n-2) \cdots (n-k+1) \over k!}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
741 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
742 @end tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
743
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
744 If @var{n} is a vector generate all combinations of the elements
9080
ec41eabf4499 Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents: 9038
diff changeset
745 of @var{n}, taken @var{k} at a time, one row per combination. The
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
746 resulting @var{c} has size @code{[nchoosek (length (@var{n}),
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
747 @var{k}), @var{k}]}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
748
9210
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
749 @code{nchoosek} works only for non-negative integer arguments; use
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
750 @code{bincoeff} for non-integer scalar arguments and for using vector
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
751 arguments to compute many coefficients at once.
a7a9eecc07b5 Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents: 9209
diff changeset
752
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
753 @seealso{bincoeff}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
754 @end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
755
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
756 @end iftex