[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
overloading a function as a structure
From: |
John W. Eaton |
Subject: |
overloading a function as a structure |
Date: |
Tue, 10 May 2005 01:23:06 -0400 |
On 9-May-2005, Tom Holroyd wrote:
| This one's particularly nasty.
|
| octave:1> grid.pos = 0
| usage: grid ("on" | "off")
| error: evaluating if command near line 40, column 3
| error: called from `grid' in file
| `/usr/local/share/octave/2.1.69/m/plot/grid.m'
|
| Matlab just tosses the definition of the grid function, and creates a
| structure called grid.
|
| Worse, this line:
|
| grid.pos = grid.pos(:,cfg.constr.expand) .* a
|
| gets a syntax error, though in Matlab it doesn't, presumably because
| grid is defined somewhere above. By itself it throws an error, but in
| the context of the function it doesn't.
|
| Is there a way to undefine a function? "clear grid" beforehand
| doesn't do it.
The problem is not that grid is a function, it's that it is marked as
a "command".
So if you do
unmark_command ("grid");
then you should be able to write
grid.pos = 0;
I see no fix for this problem that doesn't break other things. What
should happen for
ls . a = 2
? If it creates a structure called "ls" with a field named "a" having
the value 2, then that seems bad if what I really wanted was to get a
listing of the files ".", "a", "=", and "2". What if the "=" is
missing:
ls . a 2
? Then what should happen? If it produces a directory listing, then
it seems we need potentially unlimited lookahead to get this right
(there could be all kinds of crazy indexing between "ls" and "=").
If you really want these things to work in a compatible way, then I
think we need a new parser for Octave, probably implemented using
something other than Bison.
As a quick workaround, you can do
grid = [];
before you use it as a variable. Of course, this does mean that you
need to know which names have been marked as commands, so it may not
be the most convenient solution for you.
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------