octave-maintainers
[Top][All Lists]
Advanced

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

Re: Ambiguous documentation for "clear -all"


From: Michael D. Godfrey
Subject: Re: Ambiguous documentation for "clear -all"
Date: Sat, 17 Apr 2010 19:00:07 -0700
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4

On 4/17/10 5:47 PM, Rik wrote:
4/17/10

According to 'help clear', the option -all should clear local and global
symbols.

---------------------------------------------------------------------
The following options are available in both long and short form
     `-all, -a'
           Clears all local and global user-defined variables and all
           functions from the symbol table.
---------------------------------------------------------------------

However, Octave does not seem to actually remove the global variables, but
only remove them from view.  The following code shows this:

local_test_var = 1;
global global_test_var = 2;
whos
clear -all
whos
global global_test_var
global_test_var

My question is whether we need to clarify the documentation to reflect what
Octave actually does, or whether we should update Octave to do what the
documentation says it does?  It would also be useful if someone could run
the above code on Matlab ("clear -all" will need to be changed to "clear
all" for Matlab).

The documentation for Matlab's clear function is here:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/clear.html.  The
difference between "clear var" and "clear global var" is well explained.

---------------------------------------------------------------------
If name is global, clear removes it from the current workspace, but it
remains accessible to any functions declaring it global.
---------------------------------------------------------------------

So it appears, that 'clear -all' is roughly equivalent to 'clear *',
whereas I would have thought that 'clear -all' was equivalent to 'clear'
which does remove both local and global variables.  Again, maybe someone
can run the code above in Matlab and report what their parser thinks is
correct.

--Rik

here is what matlab 2009b says. Note that there are 2 changes required, which also
raise matlab compatibility questions.

First, matlab will not accept

global global_test_var = 2;


This has to be done in 2 steps.
No need to change Octave for this, I think!

Second, matlab does not accept -all. It accepts -all and -a, but they do not
appear to do anything.  You have to say: clear all.
Octave appears to be similar:
octave:1>  xx=1;
octave:2> whos
Variables in the current scope:

  Attr Name        Size                     Bytes  Class
  ==== ====        ====                     =====  =====
       ans         1x13                       111  cell
       xx          1x1                          8  double

Total is 14 elements using 119 bytes

octave:3> global global_test =3;
octave:4> whos
Variables in the current scope:

  Attr Name             Size                     Bytes  Class
  ==== ====             ====                     =====  =====
       ans              1x13                       111  cell
    g  global_test      1x1                          8  double
       xx               1x1                          8  double

Total is 15 elements using 127 bytes

octave:5> clear all
octave:6> whos
octave:7> global_test
error: `global_test' undefined near line 7 column 1
octave:7>

After that here is what matlab says:
>> clear all
>> local_test_var = 1;
>> global global_test_var
>> global_test_var = 2;
>> whos
  Name                 Size            Bytes  Class     Attributes

  global_test_var      1x1                 8  double    global
  local_test_var       1x1                 8  double

>> clear all
>> whos
>>
>>
>> global global_test_var
>> global_test_var

global_test_var =

     []

>>
=======================================
It really removes all as does Octave without the -.
So it appears that the -all behavior is the main problem.
The current behavior of both matlab and Octave seems likely
to confuse.  Maybe a warning/error for clear -all  and clear -a  ?

Michael




reply via email to

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