[Pharo-project] instVarNames vs instVarNamed:
may be this is too early but I wanted to change the value of a class instance variable Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups') Nautilus class instVarNamed: 'groups' -> error Nautilus instVarNamed: 'groups' worked I found that strange and inconsistent. I'am wrong? Stef
On 23 September 2012 12:16, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
may be this is too early but I wanted to change the value of a class instance variable
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
Nautilus class instVarNamed: 'groups' -> error
Nautilus instVarNamed: 'groups' worked
I found that strange and inconsistent. I'am wrong?
nope. i never tried to access class instance vars using this.. but it is strange, it should work.
Stef
-- Best regards, Igor Stasenko.
It's not a class var, it's an inst var of the meta class Ben On Sep 23, 2012, at 1:27 PM, Igor Stasenko wrote:
On 23 September 2012 12:16, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
may be this is too early but I wanted to change the value of a class instance variable
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
Nautilus class instVarNamed: 'groups' -> error
Nautilus instVarNamed: 'groups' worked
I found that strange and inconsistent. I'am wrong?
nope. i never tried to access class instance vars using this.. but it is strange, it should work.
Stef
-- Best regards, Igor Stasenko.
yes I know. instVarNamed: is implemented on Object this is why it looks into the object class. but reimplementing on Class would make sense. Stef On Sep 23, 2012, at 2:06 PM, Benjamin wrote:
It's not a class var, it's an inst var of the meta class
Ben On Sep 23, 2012, at 1:27 PM, Igor Stasenko wrote:
On 23 September 2012 12:16, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
may be this is too early but I wanted to change the value of a class instance variable
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
Nautilus class instVarNamed: 'groups' -> error
Nautilus instVarNamed: 'groups' worked
I found that strange and inconsistent. I'am wrong?
nope. i never tried to access class instance vars using this.. but it is strange, it should work.
Stef
-- Best regards, Igor Stasenko.
instVarNamed: is implemented on Object this is why it looks into the object class. but reimplementing on Class would make sense.
I don't see any problem here, besides the maybe confusing names... #instVarNamed: works on class-side as well, used to read the values in the living instance. What would your #instVarNamed: do?
On a class, should answer the inst of the corresponding metaclass Like when you ask the inst var of an instance, you get the inst var of the corresponding class Ben On Sep 23, 2012, at 5:15 PM, Camillo Bruni wrote:
instVarNamed: is implemented on Object this is why it looks into the object class. but reimplementing on Class would make sense.
I don't see any problem here, besides the maybe confusing names...
#instVarNamed: works on class-side as well, used to read the values in the living instance.
What would your #instVarNamed: do?
On 2012-09-23, at 17:38, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
On a class, should answer the inst of the corresponding metaclass
Like when you ask the inst var of an instance, you get the inst var of the corresponding class
Ben
but that works...., I don't get it :D Nautilus instVarNamed: #maxSize Nautilus new instVarNamed: #announcer and: Nautilus class instVarNames includes: #maxSize. Nautilus instVarNames includes: #announcer. everything fine and symmetrical here...
since groups is an instance variable on the class side Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups') ok we get the instance variables so it was strange that the class could not find the instance variable using instVarNamed: Nautilus class instVarNamed: 'groups' -> error I was confused. Stef On Sep 23, 2012, at 5:42 PM, Camillo Bruni wrote:
On 2012-09-23, at 17:38, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
On a class, should answer the inst of the corresponding metaclass
Like when you ask the inst var of an instance, you get the inst var of the corresponding class
Ben
but that works...., I don't get it :D
Nautilus instVarNamed: #maxSize Nautilus new instVarNamed: #announcer
and:
Nautilus class instVarNames includes: #maxSize. Nautilus instVarNames includes: #announcer.
everything fine and symmetrical here...
On Sun, Sep 23, 2012 at 6:55 PM, Stéphane Ducasse <stephane.ducasse@inria.fr
wrote:
since groups is an instance variable on the class side
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
ok we get the instance variables
so it was strange that the class could not find the instance variable using instVarNamed:
Nautilus class instVarNamed: 'groups' -> error
I was confused.
Looks strange to me as well. I would like that it actually works :)
Stef
On Sep 23, 2012, at 5:42 PM, Camillo Bruni wrote:
On 2012-09-23, at 17:38, Benjamin <benjamin.vanryseghem.pharo@gmail.com>
wrote:
On a class, should answer the inst of the corresponding metaclass
Like when you ask the inst var of an instance, you get the inst var of
the corresponding class
Ben
but that works...., I don't get it :D
Nautilus instVarNamed: #maxSize Nautilus new instVarNamed: #announcer
and:
Nautilus class instVarNames includes: #maxSize. Nautilus instVarNames includes: #announcer.
everything fine and symmetrical here...
-- Mariano http://marianopeck.wordpress.com
This is weird, I'm not seeing the problem at all! I've always thought of *#instVarNamed:* as a sibling method to *#instVarAt:*(which maybe is more obviously an instance method). So *anAddress instVarNamed: 'street'* would return a Street, just as *anAddress instVarAt: 2* could. But anAddress, being just an instance, doesn't need to know about its class definition directly, since it can always ask its class if it needs to, so for example *anAddress class instVarNames* would return the names of all the instance variables defined in the Address class. Now can someone please explain why that is confusing? -- Cheers, Peter On Sun, Sep 23, 2012 at 10:59 PM, Mariano Martinez Peck < marianopeck@gmail.com> wrote:
On Sun, Sep 23, 2012 at 6:55 PM, Stéphane Ducasse < stephane.ducasse@inria.fr> wrote:
since groups is an instance variable on the class side
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
ok we get the instance variables
so it was strange that the class could not find the instance variable using instVarNamed:
Nautilus class instVarNamed: 'groups' -> error
I was confused.
Looks strange to me as well. I would like that it actually works :)
Stef
On Sep 23, 2012, at 5:42 PM, Camillo Bruni wrote:
On 2012-09-23, at 17:38, Benjamin <benjamin.vanryseghem.pharo@gmail.com>
wrote:
On a class, should answer the inst of the corresponding metaclass
Like when you ask the inst var of an instance, you get the inst var of
the corresponding class
Ben
but that works...., I don't get it :D
Nautilus instVarNamed: #maxSize Nautilus new instVarNamed: #announcer
and:
Nautilus class instVarNames includes: #maxSize. Nautilus instVarNames includes: #announcer.
everything fine and symmetrical here...
-- Mariano http://marianopeck.wordpress.com
On 2012-09-23, at 23:33, Peter Hugosson-Miller <oldmanlink@gmail.com> wrote:
This is weird, I'm not seeing the problem at all!
I've always thought of *#instVarNamed:* as a sibling method to *#instVarAt:*(which maybe is more obviously an instance method). So *anAddress instVarNamed: 'street'* would return a Street, just as *anAddress instVarAt: 2* could. But anAddress, being just an instance, doesn't need to know about its class definition directly, since it can always ask its class if it needs to, so for example *anAddress class instVarNames* would return the names of all the instance variables defined in the Address class.
Now can someone please explain why that is confusing?
I don't see the problem either :P...
okay, i found what is wrong with first post (didn't read carefully). The instVarNames is a class-side protocol i.e. part of a class behavior, while instVarNamed: is an instance-side protocol i.e. "hackishly access to instance variable with given name" So, this is ok: Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups') And this is ok too: Nautilus instVarNamed: 'groups' worked because Nautilus is an instance of its metaclass. But this is wrong, since 'Nautilus class' is an instance of Metaclass, and metaclass doesn't have 'groups' variable. Nautilus class instVarNamed: 'groups' -> error -- Best regards, Igor Stasenko.
On Sep 24, 2012, at 1:56 AM, Igor Stasenko wrote:
okay, i found what is wrong with first post (didn't read carefully).
The instVarNames is a class-side protocol i.e. part of a class behavior, while instVarNamed: is an instance-side protocol i.e. "hackishly access to instance variable with given name"
Yes this is exactly my point. I think that there is a protocol missing for class to be consistent.
So, this is ok: Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
And this is ok too:
Nautilus instVarNamed: 'groups' worked
because Nautilus is an instance of its metaclass.
But this is wrong, since 'Nautilus class' is an instance of Metaclass, and metaclass doesn't have 'groups' variable.
Nautilus class instVarNamed: 'groups' -> error
-- Best regards, Igor Stasenko.
On 24 September 2012 08:53, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
On Sep 24, 2012, at 1:56 AM, Igor Stasenko wrote:
okay, i found what is wrong with first post (didn't read carefully).
The instVarNames is a class-side protocol i.e. part of a class behavior, while instVarNamed: is an instance-side protocol i.e. "hackishly access to instance variable with given name"
Yes this is exactly my point. I think that there is a protocol missing for class to be consistent.
err, what is missing? class is an object, and using #instVarNamed: on them is perfectly fine.
So, this is ok: Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
And this is ok too:
Nautilus instVarNamed: 'groups' worked
because Nautilus is an instance of its metaclass.
But this is wrong, since 'Nautilus class' is an instance of Metaclass, and metaclass doesn't have 'groups' variable.
Nautilus class instVarNamed: 'groups' -> error
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
On Sun, Sep 23, 2012 at 3:16 AM, Stéphane Ducasse <stephane.ducasse@inria.fr
wrote:
may be this is too early but I wanted to change the value of a class instance variable
Nautilus class instVarNames -> #('maxSize' 'cachedLastClasses' 'groups')
Nautilus class instVarNamed: 'groups' -> error
Nautilus instVarNamed: 'groups' worked
I found that strange and inconsistent. I'am wrong?
Read Peter Hugosson Miller's message. instVarNamed: is like instVarAt:, in fact instVarNamed: instVarName ^self instVarAt: (self class allInstVarNames indexOf: instVarName) but that's slot and better is instVarNamed: instVarName ^self instVarAt: (self class instVarIndexFor: aString asString ifAbsent: [self error: 'no such inst var']) any clearer? i.e. instVarNamed: is sent to instances to access their inst vars, not to classes to access meta data about their inst vars.
Stef
-- best, Eliot
participants (7)
-
Benjamin -
Camillo Bruni -
Eliot Miranda -
Igor Stasenko -
Mariano Martinez Peck -
Peter Hugosson-Miller -
Stéphane Ducasse