Mercurial > octave
diff libinterp/corefcn/variables.cc @ 28504:d747d57989e2 stable
doc: Better document how global variables and clear() interact (bug #57604).
* var.txi: Rewrite section on global variables.
* variables.cc (Fclear): Add a Programming Note about how clear removes only
the local copy of a global variable.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 26 Jun 2020 13:57:04 -0700 |
parents | c28b8ba841fb |
children | a39a46b4cd4e 2cbfd91aafb9 |
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc Mon Jun 22 21:38:39 2020 +0200 +++ b/libinterp/corefcn/variables.cc Fri Jun 26 13:57:04 2020 -0700 @@ -1124,7 +1124,7 @@ @deftypefn {} {} clear @deftypefnx {} {} clear @var{pattern} @dots{} @deftypefnx {} {} clear @var{options} @var{pattern} @dots{} -Delete the names matching the given @var{pattern}s from the symbol table. +Delete the names matching the given @var{pattern}s thereby freeing memory. The @var{pattern} may contain the following special characters: @@ -1192,7 +1192,7 @@ @option{-exclusive}, only one other option may appear. All options must appear before any patterns. -Programming Note: The command @code{clear @var{name}} only clears the variable +Programming Notes: The command @code{clear @var{name}} only clears the variable @var{name} when both a variable and a (shadowed) function named @var{name} are currently defined. For example, suppose you have defined a function @code{foo}, and then hidden it by performing the assignment @code{foo = 2}. @@ -1200,7 +1200,13 @@ definition and restore the definition of @code{foo} as a function. Executing @code{clear foo} a second time will clear the function definition. -@seealso{who, whos, exist, mlock} +When a local variable name, which is linked to a global variable, is cleared +only the local copy of the variable is removed. The global copy is untouched +and can be restored with @code{global @var{global_varname}}. Conversely, +@code{clear -g @var{global_varname}} will remove both the local and global +variables. + +@seealso{clearvars, who, whos, exist, mlock} @end deftypefn */) { int argc = args.length () + 1;