Mercurial > hg > octave-lojdl
changeset 1045:cb4eaa324faf
[project @ 1995-01-18 19:48:19 by jwe]
author | jwe |
---|---|
date | Wed, 18 Jan 1995 19:48:19 +0000 |
parents | 1aa6f2edd975 |
children | d1bd01d11e1e |
files | src/symtab.cc src/user-prefs.cc src/user-prefs.h src/variables.cc |
diffstat | 4 files changed, 38 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -29,6 +29,7 @@ #include "error.h" #include "variables.h" #include "utils.h" +#include "user-prefs.h" #include "tree-base.h" #include "tree-expr.h" #include "tree-const.h" @@ -621,13 +622,27 @@ { if (is_read_only ()) { - char *tag = "symbol"; if (is_variable ()) - tag = "variable"; + { + if (user_pref.read_only_constants) + { + if (user_pref.read_only_constants < 0) + { + ::warning ("redefinition of constant `%s'", nm); + return 0; + } + else + ::error ("can't redefine read-only constant `%s'", nm); + } + } else if (is_function ()) - tag = "function"; - - ::error ("can't redefine read-only %s `%s'", tag, nm); + { + ::error ("can't redefine read-only function `%s'", nm); + } + else + { + ::error ("can't redefine read-only symbol `%s'", nm); + } return 1; }
--- a/src/user-prefs.cc +++ b/src/user-prefs.cc @@ -57,6 +57,7 @@ user_pref.print_answer_id_name = 0; user_pref.print_empty_dimensions = 0; user_pref.propagate_empty_matrices = 0; + user_pref.read_only_constants = 1; user_pref.resize_on_range_error = 0; user_pref.return_last_computed_value = 0; user_pref.save_precision = 0; @@ -345,6 +346,15 @@ return 0; } +// Should built-in constants always be read only? + +int +read_only_constants (void) +{ + user_pref.read_only_constants = check_str_pref ("read_only_constants"); + + return 0; +} // When doing assignments, should we resize matrices if the indices // are outside the current bounds?
--- a/src/user-prefs.h +++ b/src/user-prefs.h @@ -41,6 +41,7 @@ int print_answer_id_name; int print_empty_dimensions; int propagate_empty_matrices; + int read_only_constants; int resize_on_range_error; int return_last_computed_value; int save_precision; @@ -82,6 +83,7 @@ extern int print_answer_id_name (void); extern int print_empty_dimensions (void); extern int propagate_empty_matrices (void); +extern int read_only_constants (void); extern int resize_on_range_error (void); extern int return_last_computed_value (void); extern int silent_functions (void);
--- a/src/variables.cc +++ b/src/variables.cc @@ -1571,6 +1571,12 @@ "true", 0, 0, 1, propagate_empty_matrices, "operations on empty matrices return an empty matrix, not an error"); +#if 0 + DEFVAR ("read_only_constants", SBV_read_only_constants, "true", 0, + 0, 1, read_only_constants, + "allow built-in constants to be modified"); +#endif + DEFVAR ("realmax", SBV_realmax, DBL_MAX, 1, 1, 1, 0, "realmax (): return largest representable floating point number");