From bug-octave-request at bevo dot che dot wisc dot edu Fri Dec 19 19:18:41 2003 Subject: documentation patch for persistent From: Quentin Spencer To: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 19 Dec 2003 19:18:17 -0600 The following patches add documentation for persistent variables. Please feel free to add to this if I missed anything. I'm not an expert on texinfo, so I may not have got everything right. *** src/help.cc.~1.129.~ 2003-07-25 22:45:11.000000000 -0500 --- src/help.cc 2003-12-19 18:28:50.000000000 -0600 *************** *** 279,284 **** --- 279,287 ---- { "if", "Begin an if block.", }, + { "persistent", + "Declare variables as persistent.", }, + { "return", "Return from a function.", }, *** doc/interpreter/var.txi.~1.18.~ 2003-09-09 12:49:13.000000000 -0500 --- doc/interpreter/var.txi 2003-12-19 19:11:09.000000000 -0600 *************** *** 55,60 **** --- 55,61 ---- at menu * Global Variables:: + * Persistent Variables:: * Status of Variables:: * Summary of Built-in Variables:: * Defaults from the Environment:: *************** *** 154,159 **** --- 155,201 ---- at DOCSTRING(isglobal) + at node Persistent Variables + at section Persistent Variables + at cindex persistent variables + at cindex @code{persistent} statement + at cindex variables, persistent + + A variable that has been declared at dfn{persistent} within a function + will retain its contents in memory between subsequent calls to the + same function. The difference between persistent variables and global + variables is that persistent variables are local in scope to a + particular function and are not visible elsewhere. + + A variable may be declared persistent using a at code{persistent} + declaration statement. The following statements are all persistent + declarations. + + at example + at group + persistent a + persistent a b + persistent c = 2 + persistent d = 3 e f = 5 + at end group + at end example + + The behavior of persistent variables is equivalent to the behavior of + static variables in C. The command at code{static} in octave is also + recognized and is equivalent to at code{persistent} dot Unlike global + variables, every initialization statement will re-initialize the + variable. For example, after executing the following code + + at example + at group + persistent pvar = 1 + persistent pvar = 2 + at end group + at end example + + at noindent + the value of the persistent variable at code{pvar} is 2. + at node Status of Variables at section Status of Variables ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------