# HG changeset patch # User jwe # Date 790458499 0 # Node ID cb4eaa324faf2fff6d62c91549fe92db338b16b8 # Parent 1aa6f2edd9752b626806a2a2a5360d2125c2b661 [project @ 1995-01-18 19:48:19 by jwe] diff -r 1aa6f2edd975 -r cb4eaa324faf src/symtab.cc --- a/src/symtab.cc Wed Jan 18 16:35:01 1995 +0000 +++ b/src/symtab.cc Wed Jan 18 19:48:19 1995 +0000 @@ -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; } diff -r 1aa6f2edd975 -r cb4eaa324faf src/user-prefs.cc --- a/src/user-prefs.cc Wed Jan 18 16:35:01 1995 +0000 +++ b/src/user-prefs.cc Wed Jan 18 19:48:19 1995 +0000 @@ -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? diff -r 1aa6f2edd975 -r cb4eaa324faf src/user-prefs.h --- a/src/user-prefs.h Wed Jan 18 16:35:01 1995 +0000 +++ b/src/user-prefs.h Wed Jan 18 19:48:19 1995 +0000 @@ -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); diff -r 1aa6f2edd975 -r cb4eaa324faf src/variables.cc --- a/src/variables.cc Wed Jan 18 16:35:01 1995 +0000 +++ b/src/variables.cc Wed Jan 18 19:48:19 1995 +0000 @@ -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");