Mercurial > octave-nkf
changeset 4686:c7ae43dfdea4
[project @ 2004-01-06 19:29:23 by jwe]
author | jwe |
---|---|
date | Tue, 06 Jan 2004 19:31:57 +0000 |
parents | 14a1c9f42f67 |
children | e95c86d48732 |
files | doc/interpreter/var.txi src/ChangeLog src/OPERATORS/op-bm-b.cc src/OPERATORS/op-bm-bm.cc src/OPERATORS/op-cm-cm.cc src/OPERATORS/op-cm-cs.cc src/OPERATORS/op-cm-m.cc src/OPERATORS/op-cm-s.cc src/OPERATORS/op-m-m.cc src/OPERATORS/op-m-s.cc src/help.cc src/ops.h src/ov-cx-mat.cc src/ov-cx-mat.h |
diffstat | 14 files changed, 77 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 <jwe@bevo.che.wisc.edu> + + * 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 <jwe@bevo.che.wisc.edu> * xpow.cc (xpow (double, double)): Avoid apparent GNU libm bug.
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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.", },
--- 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) \ { \
--- 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<ComplexNDArray>::assign (idx, rhs); } void octave_complex_matrix::assign (const octave_value_list& idx, - const Matrix& rhs) + const NDArray& rhs) { int len = idx.length ();
--- 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; }