Add a New Comment (Rich Markup)
Comment Type & Canned Response: None None > Multiple Canned Responses Fixed in development Crash with no stack trace Already fixed in newer version Fixed in stable Bad description Bad description and crash Bad stack trace Obsolete version Duplicate and not fixed Duplicate and needs more info Duplicate and fixed Need info and old
( Jump to the original submission )
Even though this this is 18 months old, I can confirm the discrepancy with Matlab.
And also 'methods', 'properties' or 'events' are illegal names for properties or events.
However they are not illegal names for methods (which I guess is so that you could overload what methods() or properties() or events() does?). So you can have:
methods function methods (self) % events or proprties a = methods (self); end end
and you will not get a syntax error. It will only spit out an error when calling the method itself. If the method does actually make sense, calling methods(obj_classname) actually executes the method 'methods' instead of listing all the methods of obj_classname.
I did some investigation into this matter and here are my results:
Using properties(), methods (), events() inside 'properties' tag is illegal:
properties prop1 = properties ('classname'); %or methods or events end
Using properties(), methods(), events() from 'methods' tag is legal:
methods function foo (self) a = methods (self); % or methods ('classname'), or properties, or events end end
Would you like me test more things out?
I just wanted to understand whether these classdef section tags (methods, events, properties, etc.) are all only keywords inside classdef blocks, and only outside of one of the sections. If that's the way things work, then I think the problem would be relatively easy to fix.
If you want to close the bug, that's fine. I do see your point. If you want the answer to what methods(self) returns, it's what you'd expect: 'foo' and 'm1'.
The way someone was using it was to try to randomly call class methods for test cases. So they had a method (within the test class):
function testShuffle (self) methodNames = methods (self); for i=1:length(methodNames) eval(['self.' methodNames{i}]); end end
Obviously the code does a little more (it actually shuffles) but that's the just of it.
Do you have some suggestions of how to get around that?
OK, so "methods" should not be considered a keyword inside a methods block. That makes sense. Also, I'm assuming that if there were a functions called properties, events, or enumerations, that they should also not be considered keywords inside functions defined in the classdef methods block? What should happen for something like this:
classdef foo methods function m1 (self) methods (self) events end end end
for example? Or what about something like this:
classdef foo enumeration properties, events, methods end end
? Does that make an enumeration with those names, or is it supposed to be an error?
When calling methods on self the interpreter calls a syntax error. Which kind of makes sense since it hasn't yet interpreted the whole class yet, however Matlab lets you do this. Let me give an example.
Consider the following code:
classdef test_methods <handle methods function tst1 (self) methodNames = methods (self); end end end %!test %! a = test_methods; %! a.tst1();
When calling 'test test_methods' the interpreter responds with:
parse error near line 6 of file [...]/test_methods.m syntax error >>> m = methods (self);
I will upload this as a file as well.
(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)
Attach Files: Comment:
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Only project members can vote.
Please enter the title of George Orwell's famous dystopian book (it's a date):
Follow 3 latest changes.
Copyright © 2022 Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. The Levitating, Meditating, Flute-playing Gnu logo is a GNU GPL'ed image provided by the Nevrax Design Team. Source Code
Powered by Savane 3.9