annotate doc/interpreter/tips.txi @ 7017:a1dbe9d80eee

[project @ 2007-10-12 21:27:11 by jwe]
author jwe
date Fri, 12 Oct 2007 21:27:37 +0000
parents 93c65f2a5668
children fd42779a8428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 @c Copyright (C) 1996, 1997, 1999, 2002, 2004, 2005, 2007 John W. Eaton
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
2 @c This is part of the Octave manual.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
3 @c For copying conditions, see the file gpl.texi.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
4
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
5 @node Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
6 @appendix Tips and Standards
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
7 @cindex tips
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
8 @cindex standards of coding style
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
9 @cindex coding standards
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
10
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
11 This chapter describes no additional features of Octave. Instead it
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
12 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
13 previous chapters.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
14
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
15 @menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
16 * Style Tips:: Writing clean and robust programs.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
17 * Coding Tips:: Making code run faster.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
18 * Comment Tips:: Conventions for writing comments.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
19 * Function Headers:: Standard headers for functions.
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
20 * Documentation Tips:: Writing readable documentation strings.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
21 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
22
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
23 @node Style Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
24 @section Writing Clean Octave Programs
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 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
27 intended for widespread use:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
28
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
29 @itemize @bullet
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
30 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
31 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
32 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
33 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
34 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
35 prefix. This helps avoid name conflicts.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
36
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
37 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
38 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
39 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
40 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
41 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
42 enough.
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 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
45 alternative common prefixes, so long as they make sense.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
46
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
47 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
48 @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
49 Octave programs.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
50
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
51 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
52 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
53 (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
54 return.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
55 @xref{Errors}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
56
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
57 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
58 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
59 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
60 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
61 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
62 @end itemize
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
63
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
64 @node Coding Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
65 @section Tips for Making Code Run Faster.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
66 @cindex execution speed
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
67 @cindex speedups
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
68
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
69 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
70
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
71 @itemize @bullet
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 Avoid looping wherever possible.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
74
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
75 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
76 Use iteration rather than recursion whenever possible.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
77 Function calls are slow in Octave.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
78
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
79 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
80 Avoid resizing matrices unnecessarily. When building a single result
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
81 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
82 first, then insert values into it. Write
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 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
85 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
86 result = zeros (big_n, big_m)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
87 for i = over:and_over
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
88 r1 = @dots{}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
89 r2 = @dots{}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
90 result (r1, r2) = new_value ();
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
91 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
92 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
93 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
94
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
95 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
96 instead of
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
97
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
98 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
99 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
100 result = [];
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
101 for i = ever:and_ever
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
102 result = [ result, new_value() ];
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
103 endfor
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
104 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
105 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
106
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
107 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
108 Avoid calling @code{eval} or @code{feval} whenever possible, because
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
109 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
110 the symbol table.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
111
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
112 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
113 because you need to execute some arbitrary text, use the @code{try}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
114 statement instead. @xref{The try Statement}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
115
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
116 @item
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
117 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
118 change during your run, set the variable
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
119 @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
120 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
121 files.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
122 @end itemize
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
123
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
124 @node Comment Tips
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
125 @section Tips on Writing Comments
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
126
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
127 Here are the conventions to follow when writing comments.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
128
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
129 @table @samp
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
130 @item #
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
131 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
132 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
133 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
134 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
135 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
136 aligns such a comment if it is already present.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
137
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
138 @item ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
139 Comments that start with two semicolons, @samp{##}, should be aligned to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
140 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
141 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
142 at that point.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
143 @end table
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
144
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
145 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
146 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
147 (@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
148 automatically indent comments according to these conventions,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
149 depending on the number of semicolons. @xref{Comments,,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
150 Manipulating Comments, emacs, The GNU Emacs Manual}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
151
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3294
diff changeset
152 @node Function Headers
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
153 @section Conventional Headers for Octave Functions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
154 @cindex header comments
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
155
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
156 Octave has conventions for using special comments in function files
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
157 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
158 conventions.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
159
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
160 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
161 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
162 Here is an example:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
163
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
164 @example
6778
083721ae3dfa [project @ 2007-07-18 17:03:10 by jwe]
jwe
parents: 6670
diff changeset
165 ## Copyright (C) 1996, 1997, 2007 John W. Eaton
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
166 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
167 ## This file is part of Octave.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
168 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
169 ## Octave is free software; you can redistribute it and/or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
170 ## modify it under the terms of the GNU General Public
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
171 ## License as published by the Free Software Foundation;
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
172 ## either version 3 of the License, or (at your option) any later
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
173 ## version.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
174 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
175 ## 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
176 ## but WITHOUT ANY WARRANTY; without even the implied
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
177 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
178 ## PURPOSE. See the GNU General Public License for more
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
179 ## details.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
180 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
181 ## 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
182 ## 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
183 ## see <http://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
184
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
185 ## usage: [IN, OUT, PID] = popen2 (COMMAND, ARGS)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
186 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
187 ## Start a subprocess with two-way communication. COMMAND
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
188 ## 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
189 ## array of strings containing options for COMMAND. IN and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
190 ## 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
191 ## subprocess, and PID is the process id of the subprocess,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
192 ## or -1 if COMMAND could not be executed.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
193 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
194 ## Example:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
195 ##
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
196 ## [in, out, pid] = popen2 ("sort", "-nr");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
197 ## fputs (in, "these\nare\nsome\nstrings\n");
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
198 ## fclose (in);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
199 ## while (isstr (s = fgets (out)))
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
200 ## fputs (stdout, s);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
201 ## endwhile
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
202 ## fclose (out);
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
203 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
204
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
205 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
206 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
207 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
208 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
209 comment characters.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
210
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
211 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
212 comment} lines, each beginning with @samp{## @var{header-name}:}. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
213 example,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
214
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
215 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
216 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
217 ## Author: jwe
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
218 ## Keywords: subprocesses input-output
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
219 ## Maintainer: jwe
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
220 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
221 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
222
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
223 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
224
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
225 @table @samp
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
226 @item Author
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
227 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
228 author of the library.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
229
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6576
diff changeset
230 @example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
231 ## Author: John W. Eaton <jwe@@bevo.che.wisc.edu>
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6576
diff changeset
232 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
233
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
234 @item Maintainer
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
235 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
236 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
237 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
238 maintainers. The example above is mildly bogus because the maintainer
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
239 line is redundant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
240
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
241 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
242 possible a function to ``send mail to the maintainer'' without
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
243 having to mine the name out by hand.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
244
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
245 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
246 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
247
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
248 @item Created
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
249 This optional line gives the original creation date of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
250 file. For historical interest only.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
251
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
252 @item Version
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
253 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
254 put them in this line.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
255
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
256 @item Adapted-By
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
257 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
258 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
259 example).
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 @item Keywords
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
262 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
263 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
264 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
265 commas, or both.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
266 @end table
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
267
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
268 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
269 @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
270 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
271 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
272
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
273 @node Documentation Tips
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
274 @section Tips for Documentation Strings
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
275
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
276 As noted above, documentation is typically in a commented header block
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
277 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
278 shown above is an unformatted string and will be displayed as is by
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
279 Octave. Here are some tips for the writing of documentation strings.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
280
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
281 @itemize @bullet
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
282 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
283 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
284 should have a documentation string.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
285
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
286 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
287 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
288 a documentation string.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
289
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
290 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
291 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
292 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
293
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
294 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
295 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
296 should also be made up of complete sentences.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
297
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
298 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
299 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
300 documentation string as an infinitive with ``to'' omitted. For
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
301 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
302 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
303 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
304 if they have proper subjects.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
305
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
306 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
307 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
308 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
309 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
310 returned.''
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
311
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
312 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
313 Avoid using the word ``cause'' (or its equivalents) unnecessarily.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
314 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
315 ``Display text in boldface.''
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
316
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
317 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
318 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
319
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
320 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
321 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
322 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
323 60 characters.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
324
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
325 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
326 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
327 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
328
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
329 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
330 @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
331 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
332 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
333 view the documentation. Remember that the indentation before the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
334 starting double-quote is not part of the string!
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
335
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
336 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
337 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
338 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
339 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
340 nonzero mean.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
341
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
342 @item
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
343 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
344 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
345 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
346 @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
347 actual argument name is @code{divisor}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
348
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
349 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
350 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
351 vary.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
352 @end itemize
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
353
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
354 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
355 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
356 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
357 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
358 or online documentation will be greatly improved.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
359
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
360 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
361 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
362 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
363 signature. Typical classes for functions include @code{Function File}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
364 for standard Octave functions, and @code{Loadable Function} for
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
365 dynamically linked functions. A skeletal Texinfo documentation string
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
366 therefore looks like this
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
367
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
368 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
369 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
370 -*- texinfo -*-
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
371 @@deftypefn@{Function File@} @{@@var@{return_value@} = @} function_name (@dots{})
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
372 @@cindex index term
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
373 Help text in Texinfo format. Code samples should be marked like
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
374 @@code@{sample of code@} and variables should be marked as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
375 @@var@{variable@}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
376 @@seealso@{function2@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
377 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
378 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
379 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
380
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
381 This help string must be commented in user functions, or in the help
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
382 string of the @code{DEFUN_DLD} macro for dynamically loadable
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
383 functions. The important aspects of the documentation string are
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
384
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
385 @table @asis
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
386 @item -*- texinfo -*-
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
387 This string signals Octave that the follow text is in Texinfo format,
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
388 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
389 @item @@deftypefn@{class@} @dots{} @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
390 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
391 deftypefn.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
392 @item @@cindex index term
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
393 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
394 included as part of a larger piece of documentation. It is ignored
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
395 within Octave's help viewer.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
396 @item @@var@{variable@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
397 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
398 is then changed appropriately for display.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
399 @item @@code@{sample of code@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
400 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
401 reasons as the @@var macro.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
402 @item @@seealso@{function2@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
403 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
404 referencing from one function documentation string to another.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
405 @end table
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
406
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
407 Texinfo format has been designed to generate output for online viewing
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
408 with text-terminals as well as generating high-quality printed output.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
409 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
410 of the document into a particular output processor. Three formats are
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
411 of importance: info, html and TeX. These are selected with
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
412
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
413 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
414 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
415 @@ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
416 Text area for info only
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
417 @@end ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
418 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
419 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
420
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
421 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
422 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
423 @@ifhtml
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
424 Text area for html only
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
425 @@end ifhtml
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
426 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
427 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
428
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
429 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
430 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
431 @@iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
432 @@tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
433 text for TeX only
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
434 @@end tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
435 @@end iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
436 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
437 @end example
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 Note that often TeX output can be used in html documents and so often
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
440 the @code{@@ifhtml} blocks are unnecessary. If no specific output
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
441 processor is chosen, by default, the text goes into all output
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
442 processors. It is usual to have the above blocks in pairs to allow the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
443 same information to be conveyed in all output formats, but with a
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
444 different markup.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
445
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
446 Another important feature of Texinfo that is often used in Octave help
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
447 strings is the @code{@@example} environment. An example of its use is
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
448
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
449 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
450 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
451 @@example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
452 @@group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
453 @@code@{2 * 2@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
454 @@result@{@} 4
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
455 @@end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
456 @@end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
457 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
458 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
459
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
460 which produces
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
461
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
462 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
463 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
464 @code{2 * 2}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
465 @result{} 4
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
466 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
467 @end example
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 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
470 page boundary, while the @code{@@result@{@}} macro produces a right
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
471 arrow signifying the result of a command.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
472
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
473 In many cases a function has multiple means in which it can be called,
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
474 and the @code{@@deftypefnx} macro can be used to give alternatives. For
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
475 example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
476
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
477 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
478 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
479 -*- texinfo -*-
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
480 @@deftypefn@{Function File@} @{@@var@{a@} = @} function_name (@@var@{x@}, @dots{})
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
481 @@deftypefnx@{Function File@} @{@@var@{a@} = @} function_name (@@var@{y@}, @dots{})
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
482 Help text in Texinfo format.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
483 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
484 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
485 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
486
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
487 Many complete examples of Texinfo documentation can be taken from the
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
488 help strings for the Octave functions themselves. A relatively complete
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
489 example of which is the @code{nchoosek} function. The Texinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
490 documentation string of @code{nchoosek} is
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
491
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
492 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
493 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
494 -*- texinfo -*-
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
495 @@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
496
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
497 Compute the binomial coefficient or all combinations of @@var@{n@}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
498 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
499 of @@var@{n@} and @@var@{k@}, defined as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
500
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
501 @@iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
502 @@tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
503 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
504 @{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
505 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
506 @@end tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
507 @@end iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
508 @@ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
509
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
510 @@example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
511 @@group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
512 / \
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
513 | n | n (n-1) (n-2) ... (n-k+1)
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
514 | | = -------------------------
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
515 | k | k!
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 @@end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
518 @@end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
519 @@end ifinfo
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
520
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6778
diff changeset
521 If @@var@{n@} is a vector, this generates all combinations of the elements
6574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
522 of @@var@{n@}, taken @@var@{k@} at a time, one row per combination. The
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
523 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
524 @@var@{k@}), @@var@{k@}]@}.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
525
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
526 @@seealso@{bincoeff@}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
527 @@end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
528 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
529 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
530
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
531 which demonstrates most of the concepts discussed above.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
532 @iftex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
533 This documentation string renders as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
534
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
535 @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
536 @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
537 @c appear with info.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
538 @example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
539 @group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
540 -- Function File: C = nchoosek (N, K)
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
541 Compute the binomial coefficient or all combinations of N. If N
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
542 is a scalar then, calculate the binomial coefficient of N and K,
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
543 defined as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
544
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
545 / \
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
546 | n | n (n-1) (n-2) ... (n-k+1)
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
547 | | = -------------------------
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
548 | k | k!
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
549 \ /
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
550
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
551 If N is a vector generate all combinations of the elements of N,
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
552 taken K at a time, one row per combination. The resulting C has
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
553 size `[nchoosek (length (N), K), K]'.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
554
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
555
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
556 See also: bincoeff.
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
557 @end group
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
558 @end example
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
559
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
560 using info, whereas in a printed documentation using TeX it will appear
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
561 as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
562
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
563 @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
564
6576
f14a0d35f90b [project @ 2007-04-25 14:22:34 by jwe]
jwe
parents: 6574
diff changeset
565 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
566 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
567 of @var{n} and @var{k}, defined as
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
568
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
569 @tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
570 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
571 {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
572 $$
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
573 @end tex
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
574
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
575 If @var{n} is a vector generate all combinations of the elements
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
576 of @var{n}, taken @var{k} at a time, one row per combination. The
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
577 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
578 @var{k}), @var{k}]}.
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 @seealso{bincoeff}
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
581 @end deftypefn
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
582
d5d6a670f137 [project @ 2007-04-25 14:02:38 by jwe]
jwe
parents: 6530
diff changeset
583 @end iftex