On 22/12/25 2:54 PM, Christopher Plewright wrote:
On Monday, 26 December 2022 at 09:08:22 UTC+11 err...@raelity.com wrote:
On 22/12/25 1:07 PM, Bram Moolenaar wrote:
With 9.0.1094, in the script that follows, attempting to read a
classMember through an instance fails;
echomsg c.classMember
should it?
No, an object does not provide a class member.
I suppose requiring the class name makes it most clear, but I recall
mention that classnames can get long. I suppose a getter could be added.
How can you access the getter without referring to the class?
Assuming c is an object
c.GetClassMember()
where the method GetClassMember() returns the classMember that was
declared static.
Can a class method (or should it be called class function?) be static?
Nothing *is* static, the "static" keyword is used to change the meaning
of items.
I should have said "can a method/function defined in a class be
declared static?"
I don't think it's a good idea to access static class function from an
object instance of that class.
I was not suggesting that. I've botched the question. I was saying that
to get a class member (something declared static) from an object, there
could be an instance method that returns the class member.
And I didn't know that it was documented that a function could be
declared static; missed that, my bad.
Also, I would not name that function with "Member" if it is a
static function, because member implies that it is a member method of
an object instance. I think that could lead to confusion for someone
else trying to read your code.
The difference between a function and a method is important - with
regard to this topic of classes vs objects of the class. According
to Bram's preliminary doco. Yes, class "method" can be declared
static. But then, I think that makes it a static class "function",
and not a class "method".
Bram, I think that the doco here is referring to a class "function",
not a class "method". It might be worth distinguishing between method
and function in the doco?
I should have studied the docs better, but yes, method for instance and
function for class works for me.
Ref:
https://github.com/vim/vim/blob/b3d614369fceb891819badc941f80f08f57831f9/runtime/doc/vim9class.txt#L261-L275
One way to look at it: is it the case that any method can be
invoked as
MyClass.SomeMethod()
and as long as "SomeMethod()" doesn't reference a variable like
"this.someVar" then it's OK?
-ernie
How would Vim know when that is an error or not, if you didn't specify
the static keyword when declaring the static class function.
I didn't know it was documented that there could be a static class
function. The whole point of the question was to determine if there
could be a static class function.
Sorry for the noise and confusion,
-ernie
You want Vim to treat it as if it was a static class function, but
wouldn't Vim need to analyse deeper to see if it uses any object
members, to be able to allow that?
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google
Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/656faf72-e6a1-452c-bd25-59c22a071115n%40googlegroups.com
<https://groups.google.com/d/msgid/vim_dev/656faf72-e6a1-452c-bd25-59c22a071115n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/17616c43-f454-b648-89b8-2cd64a74d7fa%40raelity.com.