class variable slots?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

class variable slots?

Tudor Girba-2
Hi,

As far as I see, the class variables are not slots. Is that correct? If not, how do I get the slots?

Cheers,
Doru


--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Eliot Miranda-2
Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.

HTH
 

Cheers,
Doru


--

"Every thing has its own flow"



--
best,
Eliot
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Marcus Denker-4

On 26 Nov 2014, at 19:36, Eliot Miranda <[hidden email]> wrote:

Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable

Then, I added that the Compiler actually delegates code generation for read and write
to these meta-objects, meaning you can subclass them and add special kinds of Globals 
with special semantics (just like Slot Subclasses). This could be used for e.g.active globals
that announce when changed.

But the real use-case for this is putting meta-links on these globals.

e.g. add a class TT with class var T and a method that reads it.


|link |
link :=  MetaLink new 
metaObject:  Halt;
selector: #now.

(TT classVariableNamed: #T) link: link.

TT new readT
-> halt.

This means that we can out break-points on class variables (as opposed to a single read or write).

This all needs a bit more work to be really usable… 

Marcus




Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

stepharo

Le 26/11/14 21:10, Marcus Denker a écrit :

On 26 Nov 2014, at 19:36, Eliot Miranda <[hidden email]> wrote:

Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable


but I do not get why a class variable is accessed as a global. To me it looks plain wrong.
A class variable is like a shared variable between classes. In Clos it was the same as an instance variable but with a class scope.
So could not we make that nicer.
I really find terrible and an attack against modularity to have them managed that way.
Why the compiler instead of going to Smalltalk the global namespace cannot ask the class that declares it?
Even if we would have modules I do not see why a class var should be a module global because it is not what it is.
I think that the original implementation is not aligned with the semantics.


Then, I added that the Compiler actually delegates code generation for read and write
to these meta-objects, meaning you can subclass them and add special kinds of Globals 
with special semantics (just like Slot Subclasses). This could be used for e.g.active globals
that announce when changed.

But the real use-case for this is putting meta-links on these globals.

e.g. add a class TT with class var T and a method that reads it.


|link |
link :=  MetaLink new 
metaObject:  Halt;
selector: #now.

(TT classVariableNamed: #T) link: link.

TT new readT
-> halt.

This means that we can out break-points on class variables (as opposed to a single read or write).

This all needs a bit more work to be really usable… 

Marcus





Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Marcus Denker-4

On 27 Nov 2014, at 08:09, stepharo <[hidden email]> wrote:


Le 26/11/14 21:10, Marcus Denker a écrit :

On 26 Nov 2014, at 19:36, Eliot Miranda <[hidden email]> wrote:

Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable


but I do not get why a class variable is accessed as a global.

It is not. You have to ask the class for the class variable:

SmalltalkImage classVariableNamed: #CompilerClass.

This returns the class variable ‘CompilerClass’ of class SmalltalkImage.


To me it looks plain wrong.
A class variable is like a shared variable between classes. In Clos it was the same as an instance variable but with a class scope.
So could not we make that nicer.
I really find terrible and an attack against modularity to have them managed that way.

Which way?

ah, I think my example was a bad one: I used SmalltalkIamge as it is the class that comes to my mind that uses logs
of class variables. I do not ask the global namespace anything, 

e.g. make a case TT with class var T and it is 

TT  classVariableNamed: #T

The variable is *not* global. It’s a class variable.

Marcus



Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

stepharo


but I do not get why a class variable is accessed as a global.

It is not. You have to ask the class for the class variable:

SmalltalkImage classVariableNamed: #CompilerClass.

This returns the class variable ‘CompilerClass’ of class SmalltalkImage.

ahhhh ok


To me it looks plain wrong.
A class variable is like a shared variable between classes. In Clos it was the same as an instance variable but with a class scope.
So could not we make that nicer.
I really find terrible and an attack against modularity to have them managed that way.

Which way?

ah, I think my example was a bad one: I used SmalltalkIamge as it is the class that comes to my mind that uses logs
of class variables. I do not ask the global namespace anything, 

e.g. make a case TT with class var T and it is 

TT  classVariableNamed: #T

The variable is *not* global. It’s a class variable.

Ok we are safe :)



Marcus




Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Tudor Girba-2
In reply to this post by Marcus Denker-4
Hi,

Indeed, this is what I am looking for: a dedicated object representing the class variable. This kind of objects become particularly useful in an interface like the inspector because we can define dedicated views on them. If they are generic associations or symbols, we cannot do much.

Cheers,
Doru


On Wed, Nov 26, 2014 at 9:10 PM, Marcus Denker <[hidden email]> wrote:

On 26 Nov 2014, at 19:36, Eliot Miranda <[hidden email]> wrote:

Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable

Then, I added that the Compiler actually delegates code generation for read and write
to these meta-objects, meaning you can subclass them and add special kinds of Globals 
with special semantics (just like Slot Subclasses). This could be used for e.g.active globals
that announce when changed.

But the real use-case for this is putting meta-links on these globals.

e.g. add a class TT with class var T and a method that reads it.


|link |
link :=  MetaLink new 
metaObject:  Halt;
selector: #now.

(TT classVariableNamed: #T) link: link.

TT new readT
-> halt.

This means that we can out break-points on class variables (as opposed to a single read or write).

This all needs a bit more work to be really usable… 

Marcus







--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Tudor Girba-2
In reply to this post by Eliot Miranda-2
Hi Eliot,

Thanks. I know what class variables are, I was just asking if there is a Slot-like meta-object in the implementation :).

Cheers,
Doru


On Wed, Nov 26, 2014 at 7:36 PM, Eliot Miranda <[hidden email]> wrote:
Hi Tudor,

On Wed, Nov 26, 2014 at 6:02 AM, Tudor Girba <[hidden email]> wrote:
Hi,

As far as I see, the class variables are not slots. Is that correct?

That's right.  They're associations in class pools, and are visible in the instance-side and class-side methods of the class and all its subclasses.  See Class>>bindingOf: and Class's inst var classPool.  Shared pools are similar.  A shared pool stores its variables in its class pool, but other classes can have its class vars in scope by including the shared pool in its pool dictionaries.
 
If not, how do I get the slots?

Well, just for clarity (at least I hope it'll bring clarity).  One can access the variables via

MyClass classPool associations

Note that these are entirely different from class instance variables, which are inst var slots in the class object. These hold things like the class's superclass, its method dictionary, etc.  But one can add inst vars to one's own class.  There are many examples of this.  Since these slots are per-class every class gets its own copy of the slot, and because these are inst vars, they are only in scope in class-side methods of the defining class and subclasses.

HTH
 

Cheers,
Doru


--

"Every thing has its own flow"



--
best,
Eliot



--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Marcus Denker-4
In reply to this post by Marcus Denker-4


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable


Having objects for concepts like this allows of course to leverage the power of
the tools… e.g. this adds an inspect pane that shows all users of variables:

14562 add a Users tab to GTInspector for Slots and LiteralVariables
https://pharo.fogbugz.com/f/cases/14562


Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Tudor Girba-2
Exactly! This is what I was looking for :)

Thanks,
Doru

On Wed, Dec 3, 2014 at 9:35 AM, Marcus Denker <[hidden email]> wrote:


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable


Having objects for concepts like this allows of course to leverage the power of
the tools… e.g. this adds an inspect pane that shows all users of variables:

14562 add a Users tab to GTInspector for Slots and LiteralVariables
https://pharo.fogbugz.com/f/cases/14562





--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Marcus Denker-4


On Wed, Dec 3, 2014 at 1:32 PM, Tudor Girba <[hidden email]> wrote:
Exactly! This is what I was looking for :)


This is now in 4.0 #397

e.g. use GTInspector on

Object binding

 
Thanks,
Doru

On Wed, Dec 3, 2014 at 9:35 AM, Marcus Denker <[hidden email]> wrote:


One we did for Pharo4 is to use the Associations of Globals to model these variables as meta-objects (in the same spirit as the Slot objects).

Thos means that
-> there is an Api to get them
-> they have an API to read /write

This is just “sugar” on what the associations did already:

global := SmalltalkImage classVariableNamed: #CompilerClass.
global read.
global class
==> ClassVariable


Having objects for concepts like this allows of course to leverage the power of
the tools… e.g. this adds an inspect pane that shows all users of variables:

14562 add a Users tab to GTInspector for Slots and LiteralVariables
https://pharo.fogbugz.com/f/cases/14562





--

"Every thing has its own flow"



--
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Ben Coman
Marcus Denker wrote:

>
>
> On Wed, Dec 3, 2014 at 1:32 PM, Tudor Girba <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Exactly! This is what I was looking for :)
>
>
> This is now in 4.0 #397
>
> e.g. use GTInspector on
>
> Object binding

Is it feasible to get highlighting of 'Object' as well?
cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Tudor Girba-2
What do you mean?

Doru

On Wed, Dec 3, 2014 at 2:33 PM, Ben Coman <[hidden email]> wrote:
Marcus Denker wrote:


On Wed, Dec 3, 2014 at 1:32 PM, Tudor Girba <[hidden email] <mailto:[hidden email]>> wrote:

    Exactly! This is what I was looking for :)


This is now in 4.0 #397

e.g. use GTInspector on

Object binding

Is it feasible to get highlighting of 'Object' as well?
cheers -ben




--

"Every thing has its own flow"
Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Marcus Denker-4

On 03 Dec 2014, at 14:41, Tudor Girba <[hidden email]> wrote:

What do you mean?


Highlight in the source where the reference is…

Textual highlight should be simple (I did that for other tools already).

But what we need is one with semantic knowledge… which should be easy, too.
(using the AST).
Marcus

Doru

On Wed, Dec 3, 2014 at 2:33 PM, Ben Coman <[hidden email]> wrote:
Marcus Denker wrote:


On Wed, Dec 3, 2014 at 1:32 PM, Tudor Girba <[hidden email] <mailto:[hidden email]>> wrote:

    Exactly! This is what I was looking for :)


This is now in 4.0 #397

e.g. use GTInspector on

Object binding

Is it feasible to get highlighting of 'Object' as well?
cheers -ben




--

"Every thing has its own flow"

Reply | Threaded
Open this post in threaded view
|

Re: class variable slots?

Ben Coman
In reply to this post by Tudor Girba-2
In System Browser, right-click on a class > Analyse > Class refs...
or, select some text e.g. 'Object' > Extended search...>references to it

and in both cases there is highlighting of the search for class, which I
find useful.
cheers -ben

Tudor Girba wrote:

> What do you mean?
>
> Doru
>
> On Wed, Dec 3, 2014 at 2:33 PM, Ben Coman <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Marcus Denker wrote:
>
>
>
>         On Wed, Dec 3, 2014 at 1:32 PM, Tudor Girba
>         <[hidden email] <mailto:[hidden email]>
>         <mailto:[hidden email] <mailto:[hidden email]>>> wrote:
>
>             Exactly! This is what I was looking for :)
>
>
>         This is now in 4.0 #397
>
>         e.g. use GTInspector on
>
>         Object binding
>
>
>     Is it feasible to get highlighting of 'Object' as well?
>     cheers -ben
>
>
>
>
> --
> www.tudorgirba.com <http://www.tudorgirba.com>
>
> "Every thing has its own flow"