help-octave
[Top][All Lists]
Advanced

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

Variables with same name as functions. trouble!


From: John W. Eaton
Subject: Variables with same name as functions. trouble!
Date: Thu, 21 Oct 1999 03:55:25 -0500 (CDT)

On 20-Oct-1999, Joao Cardoso <address@hidden> wrote:

| I spent several hours (dummy!) debugging some old scripts where it
| happened that I used variables with the same name as script/builtin
| functions. The error message is cryptic, and does not point to the
| correct source line where the problem is. Of course this is a (bad)
| programmer issue, but I suggest that, whenever a function name is
| overwritten with a variable, a warning message be output.
| 
| The following script illustrate the problem:
| 
| function po
| 
|     error=[1,2,3];
|     error("This is an error!\n")
| 
| endfunction
| 
| octave:76> po
| error: string type invalid as index value
| error: called from `po' in file `/u/qual/src/misc/po.m'
| 
| If the script where several dozen lines long, it would be difficult to
| find the problem...
| 
| With the 582 script files in the standard octave-2.1.14 distribution it
| is easy to make such a mistake.

OK, how about this, which I just put in the bleeding-edge sources?

  octave:1> variables_can_hide_functions = 0;
  octave:2> error = 2
  error: variable `error' hides function
  error: evaluating assignment expression near line 2, column 7
  octave:2> variables_can_hide_functions = "warn";
  octave:3> error = 2
  warning: variable `error' hides function
  error = 2
  octave:4> clear error 
  octave:5> error
  error: unspecified error
  octave:5> variables_can_hide_functions = 1;    
  octave:6> error = 2
  error = 2

It will also tell you if an assignment will hide an .m or .oct file
that defines a function.

The default value for the new variable is 1, for backward
compatibility.

jwe



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

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