# HG changeset patch # User jwe # Date 1073417517 0 # Node ID c7ae43dfdea4d0d5996f2c81bf0fc98ce6d791ce # Parent 14a1c9f42f67f836e1a0847d04cd2827c60a9c42 [project @ 2004-01-06 19:29:23 by jwe] diff -r 14a1c9f42f67 -r c7ae43dfdea4 doc/interpreter/var.txi --- a/doc/interpreter/var.txi Tue Jan 06 17:20:55 2004 +0000 +++ b/doc/interpreter/var.txi Tue Jan 06 19:31:57 2004 +0000 @@ -55,6 +55,7 @@ @menu * Global Variables:: +* Persistent Variables:: * Status of Variables:: * Summary of Built-in Variables:: * Defaults from the Environment:: @@ -154,6 +155,47 @@ @DOCSTRING(isglobal) +@node Persistent Variables +@section Persistent Variables +@cindex persistent variables +@cindex @code{persistent} statement +@cindex variables, persistent + +A variable that has been declared @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 @code{persistent} +declaration statement. The following statements are all persistent +declarations. + +@example +@group +persistent a +persistent a b +persistent c = 2 +persistent d = 3 e f = 5 +@end group +@end example + +The behavior of persistent variables is equivalent to the behavior of +static variables in C. The command @code{static} in octave is also +recognized and is equivalent to @code{persistent}. Unlike global +variables, every initialization statement will re-initialize the +variable. For example, after executing the following code + +@example +@group +persistent pvar = 1 +persistent pvar = 2 +@end group +@end example + +@noindent +the value of the persistent variable @code{pvar} is 2. + @node Status of Variables @section Status of Variables diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/ChangeLog --- a/src/ChangeLog Tue Jan 06 17:20:55 2004 +0000 +++ b/src/ChangeLog Tue Jan 06 19:31:57 2004 +0000 @@ -1,3 +1,14 @@ +2003-12-22 John W. Eaton + + * ov-cx-mat.cc (octave_complex_matrix::assign): RHS arg is N-d. + * ov-cx-mat.h: Fix decl. + + * ops.h (DEFNDASSIGNOP_FN): New macro. + * OPERATORS/op-bm-b.cc, OPERATORS/op-bm-bm.cc, + OPERATORS/op-cm-cm.cc, OPERATORS/op-cm-cs.cc, + OPERATORS/op-cm-m.cc, OPERATORS/op-cm-s.cc, OPERATORS/op-m-m.cc, + OPERATORS/op-m-s.cc: Use it instead of DEFASSIGNOP_FN. + 2003-12-19 John W. Eaton * xpow.cc (xpow (double, double)): Avoid apparent GNU libm bug. diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-bm-b.cc --- a/src/OPERATORS/op-bm-b.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-bm-b.cc Tue Jan 06 19:31:57 2004 +0000 @@ -43,7 +43,7 @@ DEFNDBINOP_FN (el_and, bool_matrix, bool, bool_array, bool, mx_el_and) DEFNDBINOP_FN (el_or, bool_matrix, bool, bool_array, bool, mx_el_or) -DEFASSIGNOP_FN (assign, bool_matrix, bool, assign) +DEFNDASSIGNOP_FN (assign, bool_matrix, bool, bool_array, assign) void install_bm_b_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-bm-bm.cc --- a/src/OPERATORS/op-bm-bm.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-bm-bm.cc Tue Jan 06 19:31:57 2004 +0000 @@ -65,7 +65,7 @@ DEFNDBINOP_FN (el_or, bool_matrix, bool_matrix, bool_array, bool_array, mx_el_or) -DEFASSIGNOP_FN (assign, bool_matrix, bool_matrix, assign) +DEFNDASSIGNOP_FN (assign, bool_matrix, bool_matrix, bool_array, assign) void install_bm_bm_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-cm-cm.cc --- a/src/OPERATORS/op-cm-cm.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-cm-cm.cc Tue Jan 06 19:31:57 2004 +0000 @@ -108,7 +108,7 @@ DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_and) DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_or) -DEFASSIGNOP_FN (assign, complex_matrix, complex_matrix, assign) +DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign) void install_cm_cm_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-cm-cs.cc --- a/src/OPERATORS/op-cm-cs.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-cm-cs.cc Tue Jan 06 19:31:57 2004 +0000 @@ -101,7 +101,7 @@ DEFNDBINOP_FN (el_and, complex_matrix, complex, complex_array, complex, mx_el_and) DEFNDBINOP_FN (el_or, complex_matrix, complex, complex_array, complex, mx_el_or) -DEFASSIGNOP_FN (assign, complex_matrix, complex, assign) +DEFNDASSIGNOP_FN (assign, complex_matrix, complex, complex_array, assign) void install_cm_cs_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-cm-m.cc --- a/src/OPERATORS/op-cm-m.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-cm-m.cc Tue Jan 06 19:31:57 2004 +0000 @@ -80,7 +80,7 @@ DEFNDBINOP_FN (el_and, complex_matrix, matrix, complex_array, array, mx_el_and) DEFNDBINOP_FN (el_or, complex_matrix, matrix, complex_array, array, mx_el_or) -DEFASSIGNOP_FN (assign, complex_matrix, matrix, assign) +DEFNDASSIGNOP_FN (assign, complex_matrix, matrix, complex_array, assign) void install_cm_m_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-cm-s.cc --- a/src/OPERATORS/op-cm-s.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-cm-s.cc Tue Jan 06 19:31:57 2004 +0000 @@ -105,7 +105,7 @@ DEFNDBINOP_FN (el_and, complex_matrix, scalar, complex_array, scalar, mx_el_and) DEFNDBINOP_FN (el_or, complex_matrix, scalar, complex_array, scalar, mx_el_or) -DEFASSIGNOP_FN (assign, complex_matrix, scalar, assign) +DEFNDASSIGNOP_FN (assign, complex_matrix, scalar, complex_array, assign) void install_cm_s_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-m-m.cc --- a/src/OPERATORS/op-m-m.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-m-m.cc Tue Jan 06 19:31:57 2004 +0000 @@ -95,7 +95,7 @@ DEFNDBINOP_FN (el_and, matrix, matrix, array, array, mx_el_and) DEFNDBINOP_FN (el_or, matrix, matrix, array, array, mx_el_or) -DEFASSIGNOP_FN (assign, matrix, matrix, assign) +DEFNDASSIGNOP_FN (assign, matrix, matrix, array, assign) void install_m_m_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/OPERATORS/op-m-s.cc --- a/src/OPERATORS/op-m-s.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/OPERATORS/op-m-s.cc Tue Jan 06 19:31:57 2004 +0000 @@ -101,7 +101,7 @@ DEFNDBINOP_FN (el_and, matrix, scalar, array, scalar, mx_el_and) DEFNDBINOP_FN (el_or, matrix, scalar, array, scalar, mx_el_or) -DEFASSIGNOP_FN (assign, matrix, scalar, assign) +DEFNDASSIGNOP_FN (assign, matrix, scalar, array, assign) void install_m_s_ops (void) diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/help.cc --- a/src/help.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/help.cc Tue Jan 06 19:31:57 2004 +0000 @@ -279,6 +279,9 @@ { "if", "Begin an if block.", }, + { "persistent", + "Declare variables as persistent.", }, + { "return", "Return from a function.", }, diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/ops.h --- a/src/ops.h Tue Jan 06 17:20:55 2004 +0000 +++ b/src/ops.h Tue Jan 06 19:31:57 2004 +0000 @@ -155,6 +155,15 @@ return octave_value (); \ } +#define DEFNDASSIGNOP_FN(name, t1, t2, e, f) \ + ASSIGNOPDECL (name) \ + { \ + CAST_BINOP_ARGS (octave_ ## t1&, const octave_ ## t2&); \ + \ + v1.f (idx, v2.e ## _value ()); \ + return octave_value (); \ + } + #define DEFASSIGNANYOP_FN(name, t1, f) \ ASSIGNOPDECL (name) \ { \ diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc Tue Jan 06 17:20:55 2004 +0000 +++ b/src/ov-cx-mat.cc Tue Jan 06 19:31:57 2004 +0000 @@ -84,14 +84,14 @@ void octave_complex_matrix::assign (const octave_value_list& idx, - const ComplexMatrix& rhs) + const ComplexNDArray& rhs) { octave_base_matrix::assign (idx, rhs); } void octave_complex_matrix::assign (const octave_value_list& idx, - const Matrix& rhs) + const NDArray& rhs) { int len = idx.length (); diff -r 14a1c9f42f67 -r c7ae43dfdea4 src/ov-cx-mat.h --- a/src/ov-cx-mat.h Tue Jan 06 17:20:55 2004 +0000 +++ b/src/ov-cx-mat.h Tue Jan 06 19:31:57 2004 +0000 @@ -81,9 +81,9 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const ComplexMatrix& rhs); + void assign (const octave_value_list& idx, const ComplexNDArray& rhs); - void assign (const octave_value_list& idx, const Matrix& rhs); + void assign (const octave_value_list& idx, const NDArray& rhs); bool is_complex_matrix (void) const { return true; }