Implementation of clear()

Ben Abbott bpabbott at mac.com
Tue Dec 25 21:20:04 CST 2007


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.

Ben




More information about the Octave-maintainers mailing list