help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Puzzled about scope/existence of globals


From: Glenn Golden
Subject: Re: Puzzled about scope/existence of globals
Date: Mon, 24 Nov 2003 09:06:31 -0700

"John W. Eaton" writes:
> On 23-Nov-2003, I wrote:
> 
> | Yes it should probably be possible to do something like this since
> | Matlab has
> | 
> |   clear global    ## clear all global variables completely
> |   clear global x  ## clear global variable x completely
> | 
> | but Octave does not currently implement this feature.
> 
> It looks like this has already been implemented,
>

:). Comforting to see that this phenomenon occasionally happens to
other people as well.  I call these "Alzheimer features".

Anyway, thanks. 'clear global x' gives the behavior I was looking
for/expecting. Thanks for implementing it, even if you did forget
about it. :)



>
> but the documentation could use some fixes.
> 

Here's a stab at it. Probably not entirely correct, but maybe it will
save you a little time.

Glenn

----------------------------------------------------------------------
 - Command: clear [-x] pattern ...
            clear [-x] global pattern ...

     When called without the `global' keyword, `clear' deletes the visible
     names matching the given patterns from the symbol table of the top-level
     workspace. Global variables may be cleared in this way -- that is,
     without using the global keyword -- and after doing so they will
     no longer be visible in the top level workspace; however, their
     existence in function workspaces is unaffected.
     
     When called with the `global' keyword, `clear' deletes the global
     variables matching the given patterns from the global symbol table.
     Globals cleared in this way no longer exist in any workspace.

     Patterns for matching variable names use the following special
     characters:

    `?'
          Match any single character.

    `*'
          Match zero or more characters.

    `[ LIST ]'
          Match the list of characters specified by LIST.  If the first
          character is `!' or `^', match all characters except those
          specified by LIST.  For example, the pattern `[a-zA-Z]' will
          match all lower and upper case alphabetic characters.

     For example, the command

          clear foo b*r

     clears the name `foo' and all names that begin with the letter `b'
     and end with the letter `r' from the top-level workspace.

     If `clear' is invoked without the `global' keyword, but with additional
     arguments specifying variable patterns, then only the visible names
     matching the arguments are cleared.  For example, suppose you have
     defined a function `foo', and then hidden it by performing the
     assignment `foo = 2'.  Executing the command `clear foo' once will
     clear the variable definition and restore the definition of `foo' as
     a function.  Executing `clear foo' a second time will clear the function
     definition.

     If `clear' is invoked without the global keyword and without any
     additional arguments, all user-defined variables (local and global)
     are cleared from the symbol table of the top-level workspace.

     If invoked as `clear global' but with no additional arguments,
     then all global variables are deleted from all workspaces.

     The -x option specifies that variables _not_ matching the patterns
     should be cleared, in accordance with the above rules. 

     This command may not be used within a function body.
----------------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]