Tue 27 Sep 2016 10:48:12 PM UTC, comment #14:
My opinion is that having `builtin("class"...)` working is more important than preventing people shooting themselves in the foot. That is, just doing the `called_from_builtin()` thing you mention sounds sufficient to me. (Just my $0.02.)
|
Tue 27 Sep 2016 09:53:51 PM UTC, comment #13:
Ok, so it's clear that we should allow class() to be called via builtin() from a class ctor function.
I don't know enough about how to traverse the Octave call stack to implement this. It is easy enough to call called_from_builtin() to detect that class() was called by builtin, but I don't easily see how to get a reference to one higher in the call stack to make sure we are in a class ctor of the same name as the 2nd argument.
If someone can supply a patch to do this, I'll be happy to test and apply.
|
Tue 27 Sep 2016 09:24:26 PM UTC, comment #12:
only remeber you only can use class to set values inside the same type or you will get the 'is not a valid class name', @foo/foo only can use foo to set the class.
|
Tue 27 Sep 2016 08:48:55 PM UTC, comment #11:
I also tried making a `foo` from within some unrelated class (`baz`). This also doesn't work:
This language is restricting my freedom to make dumb choices ;-) j/k!
Maybe it would work if the @foo class were nested inside the `@baz` directory: I didn't try that!
|
Tue 27 Sep 2016 08:45:29 PM UTC, comment #10:
Surprisingly (to me), that is indeed an error:
I can see why its a bad idea, but I don't see why its an error: I must be programming too much Python
|
Tue 27 Sep 2016 07:34:14 PM UTC, comment #9:
And if builtin('class', struct(), classname, ...) is called from a non-class method or from the top-level does Matlab detect and report an error?
|
Tue 27 Sep 2016 06:46:20 PM UTC, comment #8:
s/maybe that should work/that should work/
;-)
|
Tue 27 Sep 2016 06:44:34 PM UTC, comment #7:
The end of your comment was cut off by markup processor:
Yes, maybe that should work. The simple check in place now only makes sure that the direct caller in the call stack is a class constructor.
|
Tue 27 Sep 2016 06:43:33 PM UTC, comment #6:
Looks like something ate my verbatim in a previous comment.
What should work (and does in Matlab) is:
(also it would appear that verbatim's cannot contain lines that start with +/- like diff output).
|
Tue 27 Sep 2016 06:42:24 PM UTC, comment #5:
Matlab:
And it works using `builtin`...
|
Tue 27 Sep 2016 06:31:57 PM UTC, comment #4:
I agree that should be expected behaviour (I have also not tested on Matlab).
But what might be expected to work is the following change to your MWE:
|
Tue 27 Sep 2016 06:16:19 PM UTC, comment #3:
Ok, so that error is specifically about a constructor using inheritance from another object type that overrides the class method. I can confirm with a minimum working example:
The override behavior seems to be fairly consistent with other methods in Octave. It would be good to find out what Matlab does with an example like this before we try to guess what the right behavior should be.
|
Tue 27 Sep 2016 01:12:18 AM UTC, comment #2:
Hi Mike Miller, nice to see you again, this is where this come:
https://github.com/cbm755/octsympy/pull/561
There we need two things, first set class, and get class, there you can see what happen in all this cases.
Thx.
|
Mon 26 Sep 2016 09:24:01 PM UTC, comment #1:
This error is probably because the class function knows whether it is being called from a class constructor function or not. If you call it using builtin, that adds an indirection to the stack and it no longer knows that it is in a constructor context.
However, you don't need to use builtin to do what you want. I made a simple example to show the class I think you are describing:
It seems to work for me without needing to use builtin, probably because Octave defers calling overridden methods in the constructor.
Is there something missing in your example that shows why you need to use builtin and why you think that should work as you describe?
Do you have access to Matlab to compare and show whether they work one way or the other?
|
Fri 23 Sep 2016 08:24:11 PM UTC, original submission:
As the title says, when we use the class function to set the class works fine in @foo/foo.m, but if we instead call it directly we call it with the builtin function send the error:
error: class: 'foo' is invalid as a class name in this context
error: called from
foo at line 184 column 5
only to be clear, this works:
class(f, 'foo', expr)
this don't works:
builtin('class', f, 'foo', expr)
Why we can need call class with builtin?, when we overload the class function of @foo only to get data instead of set.
To others examples imagine!
Thx. Cya.
|