octave-maintainers
[Top][All Lists]
Advanced

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

Re: Implementation of clear()


From: Ben Abbott
Subject: Re: Implementation of clear()
Date: Wed, 26 Dec 2007 22:23:36 +0800


On Dec 26, 2007, at 5:02 PM, Thomas Weber wrote:

Am Mittwoch, den 26.12.2007, 11:20 +0800 schrieb Ben Abbott:
On Dec 26, 2007, at 3:53 AM, Thomas Weber wrote:

Hi,

the current implementation of clear() tries to mimic the M* approach  
for
a few arguments (namely all, functions, global, variables).

I think it makes sense to add "exclusive" to this list. Consider the
following (3.0.0):

==========================================
octave3.0:25> a = 1; global b = 2;
octave3.0:26> clear -exclusive b
octave3.0:27> b,a
b =  2
error: `a' undefined near line 27 column 3
==========================================
As expected, a is removed and b survives.

This functionality would be useful for me. However, it might encourage  
sloppy programming habits ... something I'm quite familiar with ;-)

==========================================
octave3.0:27> a = 1; global b = 2;
octave3.0:28> clear exclusive b
octave3.0:29> a,b
a =  1
error: `b' undefined near line 29 column 3
==========================================
Now, "b" is removed and "a" survives, which I find highly surprising.

You've asked to clear variables "b" and "exclusive". Although  
"exclusive" was not defined, there is no error in either Octave or  
Matlab when this is done. Thus, it would be equivalent to type "clear  
b", which would clear variable "b" and leave "a" as it was.

The problem is that "exclusive" is specific compared with all other long
special names in that it makes a difference if I call it with or without
a dash:

"clear all" or "clear -all" are equivalent, but
"clear exclusive" or "clear -exclusive" aren't.

hmmm ... it depends. If a variable "all" exists then "clear all" and "clear -all" are not equivalent.

For example,  if "a", "b", and "all" are defined in matlab

a = 1;
b = 2;
all = [a, b];

Then "clear all" only clears the variable "all", the variables "a" and "b" remain ... same with Octave

octave:4> clear -all
octave:5> a = 1;
octave:6> b = 2;
octave:7> all = [1,2];
octave:8> clear all
octave:9> who

*** dynamically linked functions:

dispatch

*** currently compiled functions:

pkg

*** local user variables:

__nargin__  a           b

There is much in Matlab that is supported for historical reasons. I suspect they would prefer to deprecate the "clear all" and require "clear -all".  Perhaps Octave's documentation should reflect that direction?  In which case your present implementation is fine.

In any event,  your current implementation respects the explicit syntax and ignores the implicit form. I'd be inclined to leave it alone, and encourage users to use the explicit form for "clear -all" as well.

Ben 



reply via email to

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