Selectors with underscores

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

Re: Selectors with underscores

Nicolas Cellier
2010/3/17 Yoshiki Ohshima <[hidden email]>:

> At Fri, 12 Mar 2010 20:01:41 +0100,
> Stéphane Rollandin wrote:
>>
>> > IMHO, both := and _ are wrong choices. To be consistent with selector
>> > conventions, it should have been =: ( for assign:). But I guess it is too late
>> > now.
>>
>> ah, but _ is not a selector
>>
>> now if a newly created identifier symbol was automatically bound to a
>> specific instance of ProtoObject, instead of nil which is the sole
>> instance of UndefinedObject, then =: could be implemented in ProtoObject
>> as syntactic sugar for becomeForward:
>>
>> or am I wrong here ?
>
>  Hehe.  But if a variable (say an instance variable "x" of an object
> "obj") already has a non-nil value, what does that mean?
>
>  In Smalltalk 72, the left arrow was a message to an atom, in deed.
> The index finger hand literal object can be sent a string to get an
> atom object and it in turn can receive an left arrow message with an
> argument.  You can assign atom into another variable.  You can define
> the left arrow message for a collection to mean "add" instead assign.
> For an instance variable, you can use "'s" message followed by a
> string also to get the corresponding atom in the reciver context.
>
> -- Yoshiki
>

Even in st80, instVarAt:put: and tempAt:put: still are messages
anyway. It's just that there is a nicer syntax, and an optimized
byteCode, but strictly speaking, Smalltalk does not require any
assignment, nor does it require jumps.
Think of basicAt:put:, it does nor even have a special syntax nor a
byteCode (well, maybe I should check new closure byteCodes, but no
image running).

Nicolas

Reply | Threaded
Open this post in threaded view
|

Re: Selectors with underscores

Yoshiki Ohshima-2
At Wed, 17 Mar 2010 20:44:04 +0100,
Nicolas Cellier wrote:

>
> 2010/3/17 Yoshiki Ohshima <[hidden email]>:
> > At Fri, 12 Mar 2010 20:01:41 +0100,
> > Stéphane Rollandin wrote:
> >>
> >> > IMHO, both := and _ are wrong choices. To be consistent with selector
> >> > conventions, it should have been =: ( for assign:). But I guess it is too late
> >> > now.
> >>
> >> ah, but _ is not a selector
> >>
> >> now if a newly created identifier symbol was automatically bound to a
> >> specific instance of ProtoObject, instead of nil which is the sole
> >> instance of UndefinedObject, then =: could be implemented in ProtoObject
> >> as syntactic sugar for becomeForward:
> >>
> >> or am I wrong here ?
> >
> >  Hehe.  But if a variable (say an instance variable "x" of an object
> > "obj") already has a non-nil value, what does that mean?
> >
> >  In Smalltalk 72, the left arrow was a message to an atom, in deed.
> > The index finger hand literal object can be sent a string to get an
> > atom object and it in turn can receive an left arrow message with an
> > argument.  You can assign atom into another variable.  You can define
> > the left arrow message for a collection to mean "add" instead assign.
> > For an instance variable, you can use "'s" message followed by a
> > string also to get the corresponding atom in the reciver context.
> >
> > -- Yoshiki
> >
>
> Even in st80, instVarAt:put: and tempAt:put: still are messages
> anyway. It's just that there is a nicer syntax, and an optimized
> byteCode, but strictly speaking, Smalltalk does not require any
> assignment, nor does it require jumps.
> Think of basicAt:put:, it does nor even have a special syntax nor a
> byteCode (well, maybe I should check new closure byteCodes, but no
> image running).

  The answer is yes and no, I guess.  Yes, you can even introspect
contexts objects too, so Let us say we define a class called "Quote"
and on its class side, define doesNotUnderstand: to find out the
location of the named variable.  Then you could say:

  | a b |
  Quote a gets: Quote b.
  a gets: 42.
  b  "=> evaluates to 42"

or such, by using the primitives under at:put: and friends.  Or define
#++ to increment the variable.

  But being able to dispatch on the receiver's behavior, the nicer
syntax and optimization is a problem.  If you modify the compiler and
runtime so that you can write =: to mean assignment message, it may
not be "in Smalltalk-80", in my possibly subjective view...

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

Re: Selectors with underscores

Stéphane Rollandin
In reply to this post by Yoshiki Ohshima-2
Le 17/03/2010 19:32, Yoshiki Ohshima a écrit :

> At Fri, 12 Mar 2010 20:01:41 +0100,
> Stéphane Rollandin wrote:
>>
>>> IMHO, both := and _ are wrong choices. To be consistent with selector
>>> conventions, it should have been =: ( for assign:). But I guess it is too late
>>> now.
>>
>> ah, but _ is not a selector
>>
>> now if a newly created identifier symbol was automatically bound to a
>> specific instance of ProtoObject, instead of nil which is the sole
>> instance of UndefinedObject, then =: could be implemented in ProtoObject
>> as syntactic sugar for becomeForward:
>>
>> or am I wrong here ?
>
>    Hehe.  But if a variable (say an instance variable "x" of an object
> "obj") already has a non-nil value, what does that mean?

Well, a variable always has a value, nil or non-nil, so I don't really
see your point. The thing with the nil value, is that it is shared by
all other objects having a nil value. If all nils weren't the same nil,
we could becomeForward: any of them into existence as a defined object
(in contrast with an UndefinedObject)

Is there a reason, historical or technical, why we need to have only a
unique instance of UndefinedObject ?

Stef



Reply | Threaded
Open this post in threaded view
|

Re: Selectors with underscores

Nicolas Cellier
2010/3/17 Stéphane Rollandin <[hidden email]>:

> Le 17/03/2010 19:32, Yoshiki Ohshima a écrit :
>>
>> At Fri, 12 Mar 2010 20:01:41 +0100,
>> Stéphane Rollandin wrote:
>>>
>>>> IMHO, both := and _ are wrong choices. To be consistent with selector
>>>> conventions, it should have been =: ( for assign:). But I guess it is
>>>> too late
>>>> now.
>>>
>>> ah, but _ is not a selector
>>>
>>> now if a newly created identifier symbol was automatically bound to a
>>> specific instance of ProtoObject, instead of nil which is the sole
>>> instance of UndefinedObject, then =: could be implemented in ProtoObject
>>> as syntactic sugar for becomeForward:
>>>
>>> or am I wrong here ?
>>
>>   Hehe.  But if a variable (say an instance variable "x" of an object
>> "obj") already has a non-nil value, what does that mean?
>
> Well, a variable always has a value, nil or non-nil, so I don't really see
> your point. The thing with the nil value, is that it is shared by all other
> objects having a nil value. If all nils weren't the same nil, we could
> becomeForward: any of them into existence as a defined object (in contrast
> with an UndefinedObject)
>
> Is there a reason, historical or technical, why we need to have only a
> unique instance of UndefinedObject ?
>
> Stef
>
Is there a reason why we would need two?
For the VM, it's comfortable to have a well none sole instance of
nil,true,false.

Nicolas

Reply | Threaded
Open this post in threaded view
|

assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Yoshiki Ohshima-2
In reply to this post by Stéphane Rollandin
At Wed, 17 Mar 2010 22:35:31 +0100,
Stéphane Rollandin wrote:

>
> Le 17/03/2010 19:32, Yoshiki Ohshima a écrit :
> > At Fri, 12 Mar 2010 20:01:41 +0100,
> > Stéphane Rollandin wrote:
> >>
> >>> IMHO, both := and _ are wrong choices. To be consistent with selector
> >>> conventions, it should have been =: ( for assign:). But I guess it is too late
> >>> now.
> >>
> >> ah, but _ is not a selector
> >>
> >> now if a newly created identifier symbol was automatically bound to a
> >> specific instance of ProtoObject, instead of nil which is the sole
> >> instance of UndefinedObject, then =: could be implemented in ProtoObject
> >> as syntactic sugar for becomeForward:
> >>
> >> or am I wrong here ?
> >
> >    Hehe.  But if a variable (say an instance variable "x" of an object
> > "obj") already has a non-nil value, what does that mean?
>
> Well, a variable always has a value, nil or non-nil, so I don't really
> see your point. The thing with the nil value, is that it is shared by
> all other objects having a nil value. If all nils weren't the same nil,
> we could becomeForward: any of them into existence as a defined object
> (in contrast with an UndefinedObject)

  Oh, I interpreted what you said as something like:

    | a b | "create new variables.  (identifier symbols?)"
    a gets: b.  "???"
    a gets: 3.  "one of such ProtoObject is becoming 3".
    a gets: 4.  "???"

and didn't know what would happen.

> Is there a reason, historical or technical, why we need to have only a
> unique instance of UndefinedObject ?

  Like using the value 0 to mean nil and false, it is possible.  But I
don't see it helps anything...

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Igor Stasenko
On 18 March 2010 01:08, Yoshiki Ohshima <[hidden email]> wrote:

> At Wed, 17 Mar 2010 22:35:31 +0100,
> Stéphane Rollandin wrote:
>>
>> Le 17/03/2010 19:32, Yoshiki Ohshima a écrit :
>> > At Fri, 12 Mar 2010 20:01:41 +0100,
>> > Stéphane Rollandin wrote:
>> >>
>> >>> IMHO, both := and _ are wrong choices. To be consistent with selector
>> >>> conventions, it should have been =: ( for assign:). But I guess it is too late
>> >>> now.
>> >>
>> >> ah, but _ is not a selector
>> >>
>> >> now if a newly created identifier symbol was automatically bound to a
>> >> specific instance of ProtoObject, instead of nil which is the sole
>> >> instance of UndefinedObject, then =: could be implemented in ProtoObject
>> >> as syntactic sugar for becomeForward:
>> >>
>> >> or am I wrong here ?
>> >
>> >    Hehe.  But if a variable (say an instance variable "x" of an object
>> > "obj") already has a non-nil value, what does that mean?
>>
>> Well, a variable always has a value, nil or non-nil, so I don't really
>> see your point. The thing with the nil value, is that it is shared by
>> all other objects having a nil value. If all nils weren't the same nil,
>> we could becomeForward: any of them into existence as a defined object
>> (in contrast with an UndefinedObject)
>
>  Oh, I interpreted what you said as something like:
>
>    | a b | "create new variables.  (identifier symbols?)"
>    a gets: b.  "???"
>    a gets: 3.  "one of such ProtoObject is becoming 3".
>    a gets: 4.  "???"
>
> and didn't know what would happen.
>

it won't go that way, because #becomeForward: replacing all references
to same object:

a := z.
b := z.
(here a and b pointing to same object - z)

b := x.

now, 'a' should still point to 'z', while 'b' should point to 'x'.
but if you do z becomeForward: x , then both a and b will point to x.

>> Is there a reason, historical or technical, why we need to have only a
>> unique instance of UndefinedObject ?
>
>  Like using the value 0 to mean nil and false, it is possible.  But I
> don't see it helps anything...
>
> -- Yoshiki
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Stéphane Rollandin
> it won't go that way, because #becomeForward: replacing all references
> to same object:
>
> a := z.
> b := z.
> (here a and b pointing to same object - z)
>
> b := x.
>
> now, 'a' should still point to 'z', while 'b' should point to 'x'.
> but if you do z becomeForward: x , then both a and b will point to x.

right. that's what I missed :)

Stef



Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Igor Stasenko
2010/3/18 Stéphane Rollandin <[hidden email]>:

>> it won't go that way, because #becomeForward: replacing all references
>> to same object:
>>
>> a := z.
>> b := z.
>> (here a and b pointing to same object - z)
>>
>> b := x.
>>
>> now, 'a' should still point to 'z', while 'b' should point to 'x'.
>> but if you do z becomeForward: x , then both a and b will point to x.
>
> right. that's what I missed :)
>

But, if you add an indirection, that every object slots is a unique objects,
then you can make an assignment as a message , implemented
primitively, which replacing its contents, i.e.
if 'a' is an instance variable of 'object', then

a := b.  =>  object slotA setValue: b.

a  => object slotA value

> Stef
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Bert Freudenberg
On 18.03.2010, at 09:53, Igor Stasenko wrote:

>
> 2010/3/18 Stéphane Rollandin <[hidden email]>:
>>> it won't go that way, because #becomeForward: replacing all references
>>> to same object:
>>>
>>> a := z.
>>> b := z.
>>> (here a and b pointing to same object - z)
>>>
>>> b := x.
>>>
>>> now, 'a' should still point to 'z', while 'b' should point to 'x'.
>>> but if you do z becomeForward: x , then both a and b will point to x.
>>
>> right. that's what I missed :)
>>
>
> But, if you add an indirection, that every object slots is a unique objects,
> then you can make an assignment as a message , implemented
> primitively, which replacing its contents, i.e.
> if 'a' is an instance variable of 'object', then
>
> a := b.  =>  object slotA setValue: b.
>
> a  => object slotA value

Hehe. Now how do you implement setValue:? ;)

Assignment simply is a meta-operation. If you have the expression

        a := b

then it is totally irrelevant what a points to currently. 'a' just designates where the object refered to by 'b' should be stored.

Assignment is a message to the object that holds a reference, not to the referred object itself. Depending on the kind of variable it can be implemented by sending messages to the appropriate objects.

E.g. this

        | a b |
        a := 42.
        b := a.
        ^ b

is fully equivalent to

        | a b |
        a := 42.
        thisContext at: 2 put: (thisContext at: 1).
        ^ b

because a and b are temps. In the case of instance variables, assignment is equivalent to #instVarAt:put:. In the case of global variables, it's #value:.

In any case, assignment has *nothing* to do with become.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Stéphane Rollandin
> E.g. this
>
> | a b |
> a := 42.
> b := a.
> ^ b
>
> is fully equivalent to
>
> | a b |
> a := 42.
> thisContext at: 2 put: (thisContext at: 1).
> ^ b

thanks for the clarification.

can the
        | a b |
part also be rewritten by sending messages to thisContext ?

Stef



Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Igor Stasenko
In reply to this post by Bert Freudenberg
On 18 March 2010 16:11, Bert Freudenberg <[hidden email]> wrote:

> On 18.03.2010, at 09:53, Igor Stasenko wrote:
>>
>> 2010/3/18 Stéphane Rollandin <[hidden email]>:
>>>> it won't go that way, because #becomeForward: replacing all references
>>>> to same object:
>>>>
>>>> a := z.
>>>> b := z.
>>>> (here a and b pointing to same object - z)
>>>>
>>>> b := x.
>>>>
>>>> now, 'a' should still point to 'z', while 'b' should point to 'x'.
>>>> but if you do z becomeForward: x , then both a and b will point to x.
>>>
>>> right. that's what I missed :)
>>>
>>
>> But, if you add an indirection, that every object slots is a unique objects,
>> then you can make an assignment as a message , implemented
>> primitively, which replacing its contents, i.e.
>> if 'a' is an instance variable of 'object', then
>>
>> a := b.  =>  object slotA setValue: b.
>>
>> a  => object slotA value
>
> Hehe. Now how do you implement setValue:? ;)
>
as i said - by primitive :)
In same way as at:put: is primitive.

> Assignment simply is a meta-operation. If you have the expression
>
>        a := b
>
> then it is totally irrelevant what a points to currently. 'a' just designates where the object refered to by 'b' should be stored.
>
> Assignment is a message to the object that holds a reference, not to the referred object itself. Depending on the kind of variable it can be implemented by sending messages to the appropriate objects.
>
> E.g. this
>
>        | a b |
>        a := 42.
>        b := a.
>        ^ b
>
> is fully equivalent to
>
>        | a b |
>        a := 42.
>        thisContext at: 2 put: (thisContext at: 1).
>        ^ b
>
> because a and b are temps. In the case of instance variables, assignment is equivalent to #instVarAt:put:. In the case of global variables, it's #value:.
>
> In any case, assignment has *nothing* to do with become.
>
yep.

> - Bert -
>
>
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Bert Freudenberg
In reply to this post by Stéphane Rollandin
On 18.03.2010, at 15:57, Stéphane Rollandin wrote:

>
>> E.g. this
>>
>> | a b |
>> a := 42.
>> b := a.
>> ^ b
>>
>> is fully equivalent to
>>
>> | a b |
>> a := 42.
>> thisContext at: 2 put: (thisContext at: 1).
>> ^ b
>
> thanks for the clarification.
>
> can the
> | a b |
> part also be rewritten by sending messages to thisContext ?
>
> Stef

No, because the context is allocated before the method is executed. How many temps are needed is stored in the CompiledMethod.

- Bert -



12