Slot Questions

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

Slot Questions

Sean P. DeNigris
Administrator
Stateful traits inspired me to reread the flexible object layout paper and I
came up with a few questions about slots:
- What is the plan for tool support? For example, it seems that to make
slots discoverable like any other class or message, "References to it"
should include class definitions, which should be the primary slot client.
- Why does IndexedSlot have a #name slot? I thought the index and name were
"either or" for instVars.

Thanks!



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Sean P. DeNigris
Administrator
Question #3:
Shouldn't the following (from the paper):
    slots: {
    #staff => ManySlot opposite: #boss class: Clerk.
    }
Be:
    slots: {
    #staff => (ManySlot opposite: #boss class: Clerk).
    }
Also, what is that code actually doing? Is #opposite:class: a class-side
method of ManySlot? If so, what does it return? Ah, I see now - #=>> does
some magic to accept either a Slot class or instance.

Question #4:
Given:
Object subclass: #MyClass
        slots: { #var1 => MySlot }
        classVariables: {  }
        category: ''
and
MyClass >>#var1: anObject
        var1 := anObject
MySlot>#write:to: doesn't seem to be sent when I `myClassInstance var1: 2`.
I tried to insert a halt, 1 inspect, etc. I am able to intercept #read: on
the other hand

Question #5:
I tried:
Object subclass: #MyClass
        slots: { #var1 => MySlot adjustment: 10 } "with and without () around
`MySlot adjustment: 10`"
        classVariables: {  }
        category: ''
where:
InstanceVariableSlot subclass: #MySlot
        slots: { #adjustment }
and:
adjustment
        ^ adjustment ifNil: [ 0 ]
but when I open a new browser on the class definition of MyClass, the slots
are truncated to:
slots: { #var1 => MySlot }





-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
> Object subclass: #MyClass
> slots: { #var1 => MySlot adjustment: 10 }
> classVariables: {  }
> category: ''
> …
> but when I open a new browser on the class definition of MyClass, the
> slots
> are truncated to:
> slots: { #var1 => MySlot }

It turns out that the slot is still "working" e.g. #adjustment is still
having its effect e.g.
    read: anObject
        ^ (super read: anObject) ifNotNil: [ :val | val + self adjustment ]
It's just that the class template has lost information.

Another issue:
Changing the slots in the template from "{ #var1 => MySlot adjustment: 10 }"
to "{ #var1 => MySlot adjustment: 100 }" has no effect unless I accept an
intermediate "{ #var1 }"



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

webwarrior
Sean P. DeNigris wrote

> Sean P. DeNigris wrote
>> Object subclass: #MyClass
>> slots: { #var1 => MySlot adjustment: 10 }
>> classVariables: {  }
>> category: ''
>> …
>> but when I open a new browser on the class definition of MyClass, the
>> slots
>> are truncated to:
>> slots: { #var1 => MySlot }
>
> It turns out that the slot is still "working" e.g. #adjustment is still
> having its effect e.g.
>     read: anObject
> ^ (super read: anObject) ifNotNil: [ :val | val + self adjustment ]
> It's just that the class template has lost information.
>
> Another issue:
> Changing the slots in the template from "{ #var1 => MySlot adjustment: 10
> }"
> to "{ #var1 => MySlot adjustment: 100 }" has no effect unless I accept an
> intermediate "{ #var1 }"
>
>
>
> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

That's because you need to redefine #= and #definitionString (alternatively:
redefine #printOn:) in your slot class.

Also regarding tool support: there's bug tracker entry
https://pharo.fogbugz.com/f/cases/19541/References-to-class-should-also-be-searched-in-class-definitions
<https://pharo.fogbugz.com/f/cases/19541/References-to-class-should-also-be-searched-in-class-definitions>  



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Sean P. DeNigris
Administrator
webwarrior wrote
> That's because you need to redefine #= and #definitionString
> (alternatively:
> redefine #printOn:) in your slot class.

Ah, okay. After this existing part of Slot's class comment: "For customizing
a subclass can override the meta-object-protocol methods. See subclasses for
examples."

I submitted a PR with class/method comments clarifying that:
https://github.com/pharo-project/pharo/pull/1150


webwarrior wrote
> Also regarding tool support: there's bug tracker entry

Great, thanks.



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Marcus Denker-4
In reply to this post by Sean P. DeNigris


> On 24 Mar 2018, at 21:21, Sean P. DeNigris <[hidden email]> wrote:
>
> Stateful traits inspired me to reread the flexible object layout paper and I
> came up with a few questions about slots:
> - What is the plan for tool support? For example, it seems that to make
> slots discoverable like any other class or message, "References to it"
> should include class definitions, which should be the primary slot client.

Yes, these things need to be done.. I have a very large TODO list for this but it is hard to find time

> - Why does IndexedSlot have a #name slot? I thought the index and name were
> "either or" for instVars.

This is the name of the variable. Even though an init-var is accessed by index, it still has a name
(e.g. #x in Point).

        Marcus
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
> Another issue:
> Changing the slots in the template from "{ #var1 => MySlot adjustment: 10
> }"
> to "{ #var1 => MySlot adjustment: 100 }" has no effect unless I accept an
> intermediate "{ #var1 }"

Fixed by https://pharo.fogbugz.com/f/cases/21725/



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Slot Questions

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote

> Question #4:
> Given:
> Object subclass: #MyClass
> slots: { #var1 => MySlot }
> classVariables: {  }
> category: ''
> and
> MyClass >>#var1: anObject
> var1 := anObject
> MySlot>#write:to: doesn't seem to be sent when I `myClassInstance var1:
> 2`.
> I tried to insert a halt, 1 inspect, etc. I am able to intercept #read: on
> the other hand

All issues from this thread seem to be resolved in latest Pharo 7, except
the above.

This seems like a bug if IIUC. Can anyone confirm?



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean