[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #50359] clearer documentation for difference b
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty |
Date: |
Tue, 5 Sep 2017 16:49:34 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 |
Follow-up Comment #15, bug #50359 (project octave):
Here is a thread on Matlab Central about how Matlab deals with null assignment
(https://www.mathworks.com/matlabcentral/newsreader/view_thread/310020).
The quick answer is that
x(idx) = []
is flagged by the parser and the right-handside means NULL or empty and this
triggers a delete action.
When you do the same assignment without indexing
x = [];
The parser, instead, decides that you want an empty matrix so this is
equivalent to
x = zeros (0, 0);
When you code
rhs = [];
x(idx) = rhs;
the parser knows that the right-handside is not the special pattern "[]", but
a variable so it doesn't trigger any delete action.
The prototype for subsasgn is
subsasgn (VAL, IDX, RHS)
and is equivalent to
VAL(IDX) = RHS
Now consider the case of an object which has overloaded the subsasgn function.
How can the coder know whether the user has typed
object(IDX) = [];
versus
object(IDX) = zeros (0,0);
In either case, the coder will be delivered a variable RHS. This variable
will be empty, so isempty() can not distinguish what was intended. Instead,
if you want to discover whether a delete operation was requested you need to
use isnull(). For example, maybe a particular idx is read-only. Then you
might write something like
if (isnull (RHS))
if (idx == 3)
error ("object 3 is read-only");
endif
endif
The Matlab documentation for subsasgn is here:
http://www.mathworks.com/help/matlab/ref/subsasgn.html. Conveniently for
them, they do not address this case and how you might distinguish between
deletion and assignment.
I have a thought here, though, and it might be worth investigating. If the
user writes the subsasgn function prototype as
function retval = subsasgn (VAL, IDX, varargin)
then it may be the case that the Matlab parser does not assign a value to
varargin for the NULL case. If that is true then one could write
if (nargin < 3)
% Delete operation
else
% Assignment operation
end
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?50359>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty,
Rik <=
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Ernst Reissner, 2017/09/07
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Rik, 2017/09/07
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Ernst Reissner, 2017/09/08
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Kai Torben Ohlhus, 2017/09/14
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Rik, 2017/09/14
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Kai Torben Ohlhus, 2017/09/14
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Mike Miller, 2017/09/14
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Rik, 2017/09/14
- [Octave-bug-tracker] [bug #50359] clearer documentation for difference between isnull and isempty, Kai Torben Ohlhus, 2017/09/14