From bug-octave-request at bevo dot che dot wisc dot edu Wed Nov 19 00:19:46 1997 Subject: Initial value of global variable From: "John W. Eaton" To: Maximilian Pitschi cc: bug-octave at bevo dot che dot wisc dot edu Date: Wed, 19 Nov 1997 00:17:22 -0600 On 18-Nov-1997, Maximilian Pitschi wrote: | In matlab, the initial value of a global variable | is the empty matrix, []. In octave (with --traditional), such a | variable is not defined. Here is a patch to try. It should initialize global variables to the empty matrix, along with making statements like global foo = initial_foo_value; only perform the assignment if the global foo does not already have a value. Some of the M-files distributed with Octave will also need to be changed, but the patch below does not fix them. They will be updated before the next test release (coming soon). Thanks, jwe Tue Nov 18 04:27:55 1997 John W. Eaton * pt-misc.cc (tree_global::eval): Initialize global values to `[]'. Only perform explicit initialization once. *** src/pt-misc.cc~ Fri Feb 28 15:23:32 1997 --- src/pt-misc.cc Tue Nov 18 23:55:07 1997 *************** *** 441,446 **** --- 441,451 ---- if (id) { id->link_to_global (); + + octave_value tmp = id->value (); + + if (tmp.is_undefined ()) + id->define (new tree_constant (Matrix ())); } else if (ass_expr) { *************** *** 450,456 **** && (idnt = ass_expr->left_hand_side_id ())) { idnt->link_to_global (); ! ass_expr->eval (false); } else error ("global: unable to make individual structure elements global"); --- 455,468 ---- && (idnt = ass_expr->left_hand_side_id ())) { idnt->link_to_global (); ! ! // Only perform assignment if the global symbol doesn't ! // already have a value as a variable. ! ! octave_value tmp = idnt->value (); ! ! if (tmp.is_undefined ()) ! ass_expr->eval (false); } else error ("global: unable to make individual structure elements global");