bugGNU Octave - Bugs: bug #39790, "clear" also removes...


bug #39790: "clear" also removes variables from the global workspace

Submitted by:  Julien Bect <jbect>
Submitted on:  Thu 15 Aug 2013 10:14:32 AM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Julien Bect Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Tue 04 Dec 2018 08:34:14 PM UTC, comment #11:

The original changeset no longer applied, but I implemented the intent here https://hg.savannah.gnu.org/hgweb/octave/rev/247126168d23.

Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Tue 22 Nov 2016 09:26:45 PM UTC, comment #10:

This issue is still present in Octave 4.2.0.

The code example from comment #0 gives still the same results in Octave.

There is a patch submitted in comment #4 (that still lacks the possibility to clear global variables).

Hartmut <hardy>
Thu 21 Aug 2014 12:59:10 PM UTC, comment #9:

This patch seems incomplete. It's not implementing the "clear GLOBAL x" syntax for also clearing global variables.

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Wed 20 Aug 2014 06:33:50 PM UTC, comment #8:

A patch for this bug has been provided exactly one year ago :))

Anything wrong with my patch ?

Julien Bect <jbect>
Tue 20 Aug 2013 03:55:14 PM UTC, comment #7:

You are right. The documentation issues about -x
are another item.

Best to wait until your patch has been pushed and then
see what may need to be done about doc and tests.

Thanks for the opinion about the options and their
arguments counting as arguments to clear. This seems
reasonable. But, some thought should still be given
to this ansd other items like what combinations of
options are allowed. i.e. does:

clear -g -x foo

make sense, or is global assumed? If global is assumed
is there a way to use -x but only on non-global?

And, of course, needs Matlab checking...

All this is for the new bug report.

Michael Godfrey <godfrey>
Project Member
Tue 20 Aug 2013 02:24:31 PM UTC, comment #6:

I would say that this issue (doc not clear enough about `-x', no test for the behaviour of clear with `-x', etc.) deserves another bug report, with examples of situations where the documentation is not precise enough concerning `-x'.

THIS bug report is about the Matlab-incompatible behaviour of `clear' (when called with no input arguments). I believe that my patch fixes the problem, and that the documentation is now updated accordingly. Don't you agree ?

(To answer your question anyway: `clear -x foo' is the same as `clear ("-x", "foo")' and should therefore be considered, IMO, as a call with two arguments.)

Julien Bect <jbect>
Tue 20 Aug 2013 01:53:41 PM UTC, comment #5:

This does improved the documentation, but it does not
appear to clarify the behavior of:

clear -x foo

Specifically, is this treated as a use with one or
more arguments, or is -x foo treated as an option?

It might be useful to have one or more tests which
check for correct operation of -x.


Michael Godfrey <godfrey>
Project Member
Tue 20 Aug 2013 08:18:49 AM UTC, comment #4:

Here is a new version of my patch, with doc fixes as well.

@Michael: I believe it improves on the paragraph you quote, can you tell me if it sounds better ? If not, can you be more specific on what needs to be improved ?

(file #28881)

Julien Bect <jbect>
Tue 20 Aug 2013 12:48:56 AM UTC, comment #3:

It appears that the indended behavior is implemented.
But, the documentation does not seem to give a clear
explanation. The behavior of, fo example,
clear -x x2
is not clear. A user might think that x2 is an
argument, and then use the documentation section
that says:
If 'clear' is called without any arguments, all user-defined
variables (local and global) are cleared from the symbol table. If
'clear' is called with at least one argument, only the visible
names matching the arguments are cleared.

How is the negation of this explanation to be interpreted?

Michael Godfrey <godfrey>
Project Member
Mon 19 Aug 2013 06:53:26 AM UTC, comment #2:

Here is a patch that seems to do the job.

(file #28874)

Julien Bect <jbect>
Thu 15 Aug 2013 11:26:56 AM UTC, comment #1:

Related thread on maintainers list :


Julien Bect <jbect>
Thu 15 Aug 2013 10:14:32 AM UTC, original submission:

Calling "clear" from the prompt or from within a function currently removes all variables from both the current (base or local) workspace and the global workspace.

The following code demonstrates this:

For Matlab compatibility, "clear" should only remove variables from the current (base or local) workspace, but not from the global workspace.

Julien Bect <jbect>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #28881:  jbPatch_clear_2.patch added by jbect (3KiB - text/x-patch)
file #28874:  jbPatch_clear.patch added by jbect (1KiB - text/x-patch)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by jordigh (Updated the item)
  • -email is unavailable- added by jbect (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-04 rik5 StatusPatch Submitted => Fixed
        Open/ClosedOpen => Closed
    2013-08-20 jbect Attached File- => Added jbPatch_clear_2.patch, #28881
    2013-08-19 jordigh StatusNone => Patch Submitted
    2013-08-19 jbect Attached File- => Added jbPatch_clear.patch, #28874

    Back to the top

    Powered by Savane 3.4