|
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* approachfora few arguments (namely all, functions, global, variables).I think it makes sense to add "exclusive" to this list. Consider thefollowing (3.0.0):==========================================octave3.0:25> a = 1; global b = 2;octave3.0:26> clear -exclusive boctave3.0:27> b,ab = 2error: `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 encouragesloppy programming habits ... something I'm quite familiar with ;-)==========================================octave3.0:27> a = 1; global b = 2;octave3.0:28> clear exclusive boctave3.0:29> a,ba = 1error: `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 orMatlab when this is done. Thus, it would be equivalent to type "clearb", which would clear variable "b" and leave "a" as it was. 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 |
[Prev in Thread] | Current Thread | [Next in Thread] |