Mercurial > octave-nkf
comparison doc/interpreter/basics.txi @ 19628:fe689210525c gui-release
maint: Periodic merge of stable to gui-release.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 10:05:42 -0500 |
parents | 5971c8f515a7 446c46af4b42 |
children | 0e1f5a750d00 |
comparison
equal
deleted
inserted
replaced
19624:6d75f1683ce8 | 19628:fe689210525c |
---|---|
4 @c | 4 @c |
5 @c Octave is free software; you can redistribute it and/or modify it | 5 @c Octave is free software; you can redistribute it and/or modify it |
6 @c under the terms of the GNU General Public License as published by the | 6 @c under the terms of the GNU General Public License as published by the |
7 @c Free Software Foundation; either version 3 of the License, or (at | 7 @c Free Software Foundation; either version 3 of the License, or (at |
8 @c your option) any later version. | 8 @c your option) any later version. |
9 @c | 9 @c |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | 10 @c Octave is distributed in the hope that it will be useful, but WITHOUT |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13 @c for more details. | 13 @c for more details. |
14 @c | 14 @c |
15 @c You should have received a copy of the GNU General Public License | 15 @c You should have received a copy of the GNU General Public License |
16 @c along with Octave; see the file COPYING. If not, see | 16 @c along with Octave; see the file COPYING. If not, see |
17 @c <http://www.gnu.org/licenses/>. | 17 @c <http://www.gnu.org/licenses/>. |
18 | 18 |
19 @node Getting Started | 19 @node Getting Started |
124 @cindex @code{-?} | 124 @cindex @code{-?} |
125 Print short help message and exit. | 125 Print short help message and exit. |
126 | 126 |
127 @item --image-path @var{path} | 127 @item --image-path @var{path} |
128 @cindex @code{--image-path @var{path}} | 128 @cindex @code{--image-path @var{path}} |
129 Add path to the head of the search path for images. The value of | 129 Add path to the head of the search path for images. The value of |
130 @var{path} specified on the command line will override any value of | 130 @var{path} specified on the command line will override any value of |
131 @w{@env{OCTAVE_IMAGE_PATH}} found in the environment, but not any commands | 131 @w{@env{OCTAVE_IMAGE_PATH}} found in the environment, but not any commands |
132 in the system or user startup files that set the built-in variable | 132 in the system or user startup files that set the built-in variable |
133 @w{@env{IMAGE_PATH}}. | 133 @w{@env{IMAGE_PATH}}. |
134 | 134 |
135 @item --info-file @var{filename} | 135 @item --info-file @var{filename} |
136 @cindex @code{--info-file @var{filename}} | 136 @cindex @code{--info-file @var{filename}} |
137 Specify the name of the info file to use. The value of @var{filename} | 137 Specify the name of the info file to use. The value of @var{filename} |
179 @cindex @code{--no-init-file} | 179 @cindex @code{--no-init-file} |
180 Don't read the initialization files @file{~/.octaverc} and @file{.octaverc}. | 180 Don't read the initialization files @file{~/.octaverc} and @file{.octaverc}. |
181 | 181 |
182 @item --no-init-path | 182 @item --no-init-path |
183 @cindex @code{--no-init-path} | 183 @cindex @code{--no-init-path} |
184 Don't initialize the search path for function files to include default | 184 Don't initialize the search path for function files to include default |
185 locations. | 185 locations. |
186 | 186 |
187 @item --no-line-editing | 187 @item --no-line-editing |
188 @cindex @code{--no-line-editing} | 188 @cindex @code{--no-line-editing} |
189 Disable command-line editing. | 189 Disable command-line editing. |
208 | 208 |
209 @item --path @var{path} | 209 @item --path @var{path} |
210 @itemx -p @var{path} | 210 @itemx -p @var{path} |
211 @cindex @code{--path @var{path}} | 211 @cindex @code{--path @var{path}} |
212 @cindex @code{-p @var{path}} | 212 @cindex @code{-p @var{path}} |
213 Add path to the head of the search path for function files. The | 213 Add path to the head of the search path for function files. The |
214 value of @var{path} specified on the command line will override any value | 214 value of @var{path} specified on the command line will override any value |
215 of @w{@env{OCTAVE_PATH}} found in the environment, but not any commands in the | 215 of @w{@env{OCTAVE_PATH}} found in the environment, but not any commands in the |
216 system or user startup files that set the internal load path through one | 216 system or user startup files that set the internal load path through one |
217 of the path functions. | 217 of the path functions. |
218 | 218 |
290 @item @var{file} | 290 @item @var{file} |
291 Execute commands from @var{file}. Exit when done unless | 291 Execute commands from @var{file}. Exit when done unless |
292 @option{--persist} is also specified. | 292 @option{--persist} is also specified. |
293 @end table | 293 @end table |
294 | 294 |
295 Octave also includes several functions which return information | 295 Octave also includes several functions which return information |
296 about the command line, including the number of arguments and all of the | 296 about the command line, including the number of arguments and all of the |
297 options. | 297 options. |
298 | 298 |
299 @DOCSTRING(argv) | 299 @DOCSTRING(argv) |
300 | 300 |
301 @DOCSTRING(program_name) | 301 @DOCSTRING(program_name) |
302 | 302 |
303 @DOCSTRING(program_invocation_name) | 303 @DOCSTRING(program_invocation_name) |
304 | 304 |
305 Here is an example of using these functions to reproduce the command | 305 Here is an example of using these functions to reproduce the command |
306 line which invoked Octave. | 306 line which invoked Octave. |
307 | 307 |
308 @example | 308 @example |
309 @group | 309 @group |
310 printf ("%s", program_name ()); | 310 printf ("%s", program_name ()); |
316 @end group | 316 @end group |
317 @end example | 317 @end example |
318 | 318 |
319 @noindent | 319 @noindent |
320 @xref{Indexing Cell Arrays}, for an explanation of how to retrieve objects | 320 @xref{Indexing Cell Arrays}, for an explanation of how to retrieve objects |
321 from cell arrays, and @ref{Defining Functions}, for information about the | 321 from cell arrays, and @ref{Defining Functions}, for information about the |
322 variable @code{nargin}. | 322 variable @code{nargin}. |
323 | 323 |
324 @node Startup Files | 324 @node Startup Files |
325 @subsection Startup Files | 325 @subsection Startup Files |
326 @cindex initialization | 326 @cindex initialization |
335 @table @code | 335 @table @code |
336 @item @var{octave-home}/share/octave/site/m/startup/octaverc | 336 @item @var{octave-home}/share/octave/site/m/startup/octaverc |
337 @cindex site startup file | 337 @cindex site startup file |
338 where @var{octave-home} is the directory in which Octave is installed | 338 where @var{octave-home} is the directory in which Octave is installed |
339 (the default is @file{/usr/local}). | 339 (the default is @file{/usr/local}). |
340 This file is provided so that changes to the default Octave environment | 340 This file is provided so that changes to the default Octave environment |
341 can be made globally for all users at your site for all versions of Octave | 341 can be made globally for all users at your site for all versions of Octave |
342 you have installed. Care should be taken when making changes to this file | 342 you have installed. Care should be taken when making changes to this file |
343 since all users of Octave at your site will be affected. The default file | 343 since all users of Octave at your site will be affected. The default file |
344 may be overridden by the environment variable @w{@env{OCTAVE_SITE_INITFILE}}. | 344 may be overridden by the environment variable @w{@env{OCTAVE_SITE_INITFILE}}. |
345 | 345 |
346 @item @var{octave-home}/share/octave/@var{version}/m/startup/octaverc | 346 @item @var{octave-home}/share/octave/@var{version}/m/startup/octaverc |
347 @cindex version startup file | 347 @cindex version startup file |
348 where @var{octave-home} is the directory in which Octave is | 348 where @var{octave-home} is the directory in which Octave is |
355 @w{@env{OCTAVE_VERSION_INITFILE}}. | 355 @w{@env{OCTAVE_VERSION_INITFILE}}. |
356 | 356 |
357 @item ~/.octaverc | 357 @item ~/.octaverc |
358 @cindex personal startup file | 358 @cindex personal startup file |
359 @cindex @code{~/.octaverc} | 359 @cindex @code{~/.octaverc} |
360 This file is used to make personal changes to the default | 360 This file is used to make personal changes to the default |
361 Octave environment. | 361 Octave environment. |
362 | 362 |
363 @item .octaverc | 363 @item .octaverc |
364 @cindex project startup file | 364 @cindex project startup file |
365 @cindex @code{.octaverc} | 365 @cindex @code{.octaverc} |
455 @cindex editing the command line | 455 @cindex editing the command line |
456 | 456 |
457 Octave uses the GNU Readline library to provide an extensive set of | 457 Octave uses the GNU Readline library to provide an extensive set of |
458 command-line editing and history features. Only the most common | 458 command-line editing and history features. Only the most common |
459 features are described in this manual. In addition, all of the editing | 459 features are described in this manual. In addition, all of the editing |
460 functions can be bound to different key strokes at the user's discretion. | 460 functions can be bound to different key strokes at the user's discretion. |
461 This manual assumes no changes from the default Emacs bindings. See the GNU | 461 This manual assumes no changes from the default Emacs bindings. See the GNU |
462 Readline Library manual for more information on customizing Readline and | 462 Readline Library manual for more information on customizing Readline and |
463 for a complete feature list. | 463 for a complete feature list. |
464 | 464 |
465 To insert printing characters (letters, digits, symbols, etc.), simply | 465 To insert printing characters (letters, digits, symbols, etc.), simply |
466 type the character. Octave will insert the character at the cursor and | 466 type the character. Octave will insert the character at the cursor and |
467 advance the cursor forward. | 467 advance the cursor forward. |
470 characters. For example, the character @kbd{Control-a} moves the cursor | 470 characters. For example, the character @kbd{Control-a} moves the cursor |
471 to the beginning of the line. To type @kbd{C-a}, hold down @key{CTRL} | 471 to the beginning of the line. To type @kbd{C-a}, hold down @key{CTRL} |
472 and then press @key{a}. In the following sections, control characters | 472 and then press @key{a}. In the following sections, control characters |
473 such as @kbd{Control-a} are written as @kbd{C-a}. | 473 such as @kbd{Control-a} are written as @kbd{C-a}. |
474 | 474 |
475 Another set of command-line editing functions use Meta characters. To | 475 Another set of command-line editing functions use Meta characters. To |
476 type @kbd{M-u}, hold down the @key{META} key and press @key{u}. Depending | 476 type @kbd{M-u}, hold down the @key{META} key and press @key{u}. Depending |
477 on the keyboard, the @key{META} key may be labeled @key{ALT} or | 477 on the keyboard, the @key{META} key may be labeled @key{ALT} or |
478 even @key{WINDOWS}. If your terminal does not have a @key{META} key, you | 478 even @key{WINDOWS}. If your terminal does not have a @key{META} key, you |
479 can still type Meta characters using two-character sequences starting | 479 can still type Meta characters using two-character sequences starting |
480 with @kbd{ESC}. Thus, to enter @kbd{M-u}, you would type | 480 with @kbd{ESC}. Thus, to enter @kbd{M-u}, you would type |
574 Kill from the cursor to the end of the current word, or if between | 574 Kill from the cursor to the end of the current word, or if between |
575 words, to the end of the next word. | 575 words, to the end of the next word. |
576 | 576 |
577 @item M-@key{DEL} | 577 @item M-@key{DEL} |
578 Kill from the cursor to the start of the previous word, or if between | 578 Kill from the cursor to the start of the previous word, or if between |
579 words, to the start of the previous word. | 579 words, to the start of the previous word. |
580 | 580 |
581 @item C-w | 581 @item C-w |
582 Kill from the cursor to the previous whitespace. This is different than | 582 Kill from the cursor to the previous whitespace. This is different than |
583 @kbd{M-@key{DEL}} because the word boundaries differ. | 583 @kbd{M-@key{DEL}} because the word boundaries differ. |
584 @end table | 584 @end table |
703 @item C-s | 703 @item C-s |
704 Search forward starting at the current line and moving `down' through | 704 Search forward starting at the current line and moving `down' through |
705 the history as necessary. | 705 the history as necessary. |
706 @end table | 706 @end table |
707 | 707 |
708 On most terminals, you can also use the up and down arrow keys in place | 708 On most terminals, you can also use the up and down arrow keys in place |
709 of @kbd{C-p} and @kbd{C-n} to move through the history list. | 709 of @kbd{C-p} and @kbd{C-n} to move through the history list. |
710 | 710 |
711 In addition to the keyboard commands for moving through the history | 711 In addition to the keyboard commands for moving through the history |
712 list, Octave provides three functions for viewing, editing, and | 712 list, Octave provides three functions for viewing, editing, and |
713 re-running chunks of commands from the history list. | 713 re-running chunks of commands from the history list. |
902 | 902 |
903 In the example above, the first line indicates that a variable named | 903 In the example above, the first line indicates that a variable named |
904 @samp{x} was found to be undefined near line 1 and column 24 of some | 904 @samp{x} was found to be undefined near line 1 and column 24 of some |
905 function or expression. For errors occurring within functions, lines | 905 function or expression. For errors occurring within functions, lines |
906 are counted from the beginning of the file containing the function | 906 are counted from the beginning of the file containing the function |
907 definition. For errors occurring outside of an enclosing function, | 907 definition. For errors occurring outside of an enclosing function, |
908 the line number indicates the input line number, which is usually displayed | 908 the line number indicates the input line number, which is usually displayed |
909 in the primary prompt string. | 909 in the primary prompt string. |
910 | 910 |
911 The second and third lines of the error message indicate that the error | 911 The second and third lines of the error message indicate that the error |
912 occurred within the function @code{f}. If the function @code{f} had been | 912 occurred within the function @code{f}. If the function @code{f} had been |
913 called from within another function, for example, @code{g}, the list of | 913 called from within another function, for example, @code{g}, the list of |
914 errors would have ended with one more line: | 914 errors would have ended with one more line: |
915 | 915 |
916 @example | 916 @example |
917 error: g at line 1, column 17 | 917 error: g at line 1, column 17 |
918 @end example | 918 @end example |
984 printing the normal startup message, and to keep them from behaving | 984 printing the normal startup message, and to keep them from behaving |
985 differently depending on the contents of a particular user's | 985 differently depending on the contents of a particular user's |
986 @file{~/.octaverc} file. @xref{Invoking Octave from the Command Line}. | 986 @file{~/.octaverc} file. @xref{Invoking Octave from the Command Line}. |
987 | 987 |
988 Note that some operating systems may place a limit on the number of | 988 Note that some operating systems may place a limit on the number of |
989 characters that are recognized after @samp{#!}. Also, the arguments | 989 characters that are recognized after @samp{#!}. Also, the arguments |
990 appearing in a @samp{#!} line are parsed differently by various | 990 appearing in a @samp{#!} line are parsed differently by various |
991 shells/systems. The majority of them group all the arguments together in one | 991 shells/systems. The majority of them group all the arguments together in one |
992 string and pass it to the interpreter as a single argument. In this case, the | 992 string and pass it to the interpreter as a single argument. In this case, the |
993 following script: | 993 following script: |
994 | 994 |
995 @example | 995 @example |
996 @group | 996 @group |
1007 @end group | 1007 @end group |
1008 @end example | 1008 @end example |
1009 | 1009 |
1010 @noindent | 1010 @noindent |
1011 which will produce an error message. Unfortunately, it is | 1011 which will produce an error message. Unfortunately, it is |
1012 not possible for Octave to determine whether it has been called from the | 1012 not possible for Octave to determine whether it has been called from the |
1013 command line or from a @samp{#!} script, so some care is needed when using the | 1013 command line or from a @samp{#!} script, so some care is needed when using the |
1014 @samp{#!} mechanism. | 1014 @samp{#!} mechanism. |
1015 | 1015 |
1016 Note that when Octave is started from an executable script, the built-in | 1016 Note that when Octave is started from an executable script, the built-in |
1017 function @code{argv} returns a cell array containing the command line | 1017 function @code{argv} returns a cell array containing the command line |
1037 @cindex comments | 1037 @cindex comments |
1038 @cindex use of comments | 1038 @cindex use of comments |
1039 @cindex documenting Octave programs | 1039 @cindex documenting Octave programs |
1040 | 1040 |
1041 A @dfn{comment} is some text that is included in a program for the sake | 1041 A @dfn{comment} is some text that is included in a program for the sake |
1042 of human readers, and which is NOT an executable part of the program. | 1042 of human readers, and which is NOT an executable part of the program. |
1043 Comments can explain what the program does, and how it works. Nearly all | 1043 Comments can explain what the program does, and how it works. Nearly all |
1044 programming languages have provisions for comments, because programs are | 1044 programming languages have provisions for comments, because programs are |
1045 typically hard to understand without them. | 1045 typically hard to understand without them. |
1046 | 1046 |
1047 @menu | 1047 @menu |
1062 shows whole line and partial line comments. | 1062 shows whole line and partial line comments. |
1063 | 1063 |
1064 @example | 1064 @example |
1065 @group | 1065 @group |
1066 function countdown | 1066 function countdown |
1067 # Count down for main rocket engines | 1067 # Count down for main rocket engines |
1068 disp (3); | 1068 disp (3); |
1069 disp (2); | 1069 disp (2); |
1070 disp (1); | 1070 disp (1); |
1071 disp ("Blast Off!"); # Rocket leaves pad | 1071 disp ("Blast Off!"); # Rocket leaves pad |
1072 endfunction | 1072 endfunction |
1078 @cindex block comments | 1078 @cindex block comments |
1079 @cindex multi-line comments | 1079 @cindex multi-line comments |
1080 @cindex @samp{#@{} | 1080 @cindex @samp{#@{} |
1081 @cindex @samp{%@{} | 1081 @cindex @samp{%@{} |
1082 | 1082 |
1083 Entire blocks of code can be commented by enclosing the code between | 1083 Entire blocks of code can be commented by enclosing the code between |
1084 matching @samp{#@{} and @samp{#@}} or @samp{%@{} and @samp{%@}} markers. | 1084 matching @samp{#@{} and @samp{#@}} or @samp{%@{} and @samp{%@}} markers. |
1085 For example, | 1085 For example, |
1086 | 1086 |
1087 @example | 1087 @example |
1088 @group | 1088 @group |
1089 function quick_countdown | 1089 function quick_countdown |
1090 # Count down for main rocket engines | 1090 # Count down for main rocket engines |
1091 disp (3); | 1091 disp (3); |
1092 #@{ | 1092 #@{ |
1093 disp (2); | 1093 disp (2); |
1094 disp (1); | 1094 disp (1); |
1095 #@} | 1095 #@} |
1150 throw-away Octave programs, it usually isn't very useful because the | 1150 throw-away Octave programs, it usually isn't very useful because the |
1151 purpose of a comment is to help you or another person understand the | 1151 purpose of a comment is to help you or another person understand the |
1152 program at a later time. | 1152 program at a later time. |
1153 | 1153 |
1154 The @code{help} parser currently only recognizes single line comments | 1154 The @code{help} parser currently only recognizes single line comments |
1155 (@pxref{Single Line Comments}) and not block comments for the initial | 1155 (@pxref{Single Line Comments}) and not block comments for the initial |
1156 help text. | 1156 help text. |