Two-way become exists in VA Smalltalk already

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

Two-way become exists in VA Smalltalk already

Richard Sargent
Administrator
[Instantiations, please be sure to preserve this functionality if you don't implement an official two-way become.]

In porting GBS functionality from VisualWorks to VA Smalltalk, I needed two-way become support. Mark van Gulik posted an algorithm by which one can simulate two-way become using a one-way become (see below), but it required two copy operations and two separate become operations.

It turns out the #multiBecome: will do a two-way become if you convert a,b to b,a.

Example:
| date time dateHolder timeHolder |
date
:= Date today.
time
:= Time now.
dateHolder
:= Array with: date.
timeHolder
:= Array with: time.
(Array with: date with: time) multiBecome: (Array with: time with: date).
^Array with: dateHolder "now time" with: timeHolder "now date"


Mark's explanation of how to do it using brute force:
Just as a curiosity, simulating a two-way become with a one-way become
is a lot more efficient...
    aPrime := A shallowCopy.
    bPrime := B shallowCopy.
    A oneWayBecome: bPrime.
    B oneWayBecome: aPrime.
This one's cute because both objects are replaced with copies, and nobody
knows they're not the originals (like InvasionOfBodySnatchers).  One of
the copies can be avoided, but it's not like that's going to be a major
bottleneck (unless you're fiddling with huge collections).


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Two-way become exists in VA Smalltalk already

Richard Sargent
Administrator
By the way, the following is not complete. The VA Smalltalk #become: and #multiBecome: do not swap the #basicHash of the objects (which would break their use in hashed collections). So be sure to save and reset/swap their hashes in any "become" operation in VA Smalltalk.

On Tuesday, September 30, 2014 9:14:39 AM UTC-7, Richard Sargent wrote:
[Instantiations, please be sure to preserve this functionality if you don't implement an official two-way become.]

In porting GBS functionality from VisualWorks to VA Smalltalk, I needed two-way become support. Mark van Gulik posted an algorithm by which one can simulate two-way become using a one-way become (see below), but it required two copy operations and two separate become operations.

It turns out the #multiBecome: will do a two-way become if you convert a,b to b,a.

Example:
| date time dateHolder timeHolder |
date
:= Date today.
time
:= Time now.
dateHolder
:= Array with: date.
timeHolder
:= Array with: time.
(Array with: date with: time) multiBecome: (Array with: time with: date).
^Array with: dateHolder "now time" with: timeHolder "now date"


Mark's explanation of how to do it using brute force:
Just as a curiosity, simulating a two-way become with a one-way become
is a lot more efficient...
    aPrime := A shallowCopy.
    bPrime := B shallowCopy.
    A oneWayBecome: bPrime.
    B oneWayBecome: aPrime.
This one's cute because both objects are replaced with copies, and nobody
knows they're not the originals (like InvasionOfBodySnatchers).  One of
the copies can be avoided, but it's not like that's going to be a major
bottleneck (unless you're fiddling with huge collections).


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Two-way become exists in VA Smalltalk already

Seth Berman
Hi Richard,

Yes, we plan to preserve the functionality we have.
For next release we will review basicHash swapping.  I would like to understand the rationale behind the decision that was made originally not to do it...and what happens (if anything) if we do.
I found this old thread (http://forum.world.st/identityHash-and-become-question-td1404098.html) as a start for research.  I don't have much time at the moment to dig deeper, but as I said, it will be revisited.
If you have additional thoughts on the matter, I will be sure to include that in the discussion.  Thanks.

-- Seth

On Tuesday, September 30, 2014 12:37:04 PM UTC-4, Richard Sargent wrote:
By the way, the following is not complete. The VA Smalltalk #become: and #multiBecome: do not swap the #basicHash of the objects (which would break their use in hashed collections). So be sure to save and reset/swap their hashes in any "become" operation in VA Smalltalk.

On Tuesday, September 30, 2014 9:14:39 AM UTC-7, Richard Sargent wrote:
[Instantiations, please be sure to preserve this functionality if you don't implement an official two-way become.]

In porting GBS functionality from VisualWorks to VA Smalltalk, I needed two-way become support. Mark van Gulik posted an algorithm by which one can simulate two-way become using a one-way become (see below), but it required two copy operations and two separate become operations.

It turns out the #multiBecome: will do a two-way become if you convert a,b to b,a.

Example:
| date time dateHolder timeHolder |
date
:= Date today.
time
:= Time now.
dateHolder
:= Array with: date.
timeHolder
:= Array with: time.
(Array with: date with: time) multiBecome: (Array with: time with: date).
^Array with: dateHolder "now time" with: timeHolder "now date"


Mark's explanation of how to do it using brute force:
Just as a curiosity, simulating a two-way become with a one-way become
is a lot more efficient...
    aPrime := A shallowCopy.
    bPrime := B shallowCopy.
    A oneWayBecome: bPrime.
    B oneWayBecome: aPrime.
This one's cute because both objects are replaced with copies, and nobody
knows they're not the originals (like InvasionOfBodySnatchers).  One of
the copies can be avoided, but it's not like that's going to be a major
bottleneck (unless you're fiddling with huge collections).


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Two-way become exists in VA Smalltalk already

Richard Sargent
Administrator
On Wednesday, October 1, 2014 12:25:27 PM UTC-7, Seth Berman wrote:
Hi Richard,

Yes, we plan to preserve the functionality we have.
For next release we will review basicHash swapping.  I would like to understand the rationale behind the decision that was made originally not to do it...and what happens (if anything) if we do.
I found this old thread (<a href="http://forum.world.st/identityHash-and-become-question-td1404098.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;">http://forum.world.st/identityHash-and-become-question-td1404098.html) as a start for research.  I don't have much time at the moment to dig deeper, but as I said, it will be revisited.
If you have additional thoughts on the matter, I will be sure to include that in the discussion.  Thanks

Thanks, Seth. That was a very interesting and - I think - enlightening reference. It may well be that my changing their identity hashes when I swap them is actually creating problems for me. I'll have to check this out carefully. [I don't know about anyone else, but for me, "reasoning" about #become: is very difficult! :-)]

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Two-way become exists in VA Smalltalk already

Seth Berman
+1 on reasoning about #become:)

On Wednesday, October 1, 2014 3:46:58 PM UTC-4, Richard Sargent wrote:
On Wednesday, October 1, 2014 12:25:27 PM UTC-7, Seth Berman wrote:
Hi Richard,

Yes, we plan to preserve the functionality we have.
For next release we will review basicHash swapping.  I would like to understand the rationale behind the decision that was made originally not to do it...and what happens (if anything) if we do.
I found this old thread (<a href="http://forum.world.st/identityHash-and-become-question-td1404098.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;">http://forum.world.st/identityHash-and-become-question-td1404098.html) as a start for research.  I don't have much time at the moment to dig deeper, but as I said, it will be revisited.
If you have additional thoughts on the matter, I will be sure to include that in the discussion.  Thanks

Thanks, Seth. That was a very interesting and - I think - enlightening reference. It may well be that my changing their identity hashes when I swap them is actually creating problems for me. I'll have to check this out carefully. [I don't know about anyone else, but for me, "reasoning" about #become: is very difficult! :-)]

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Two-way become exists in VA Smalltalk already

Richard Sargent
Administrator
In reply to this post by Richard Sargent
On Wednesday, October 1, 2014 12:46:58 PM UTC-7, Richard Sargent wrote:
On Wednesday, October 1, 2014 12:25:27 PM UTC-7, Seth Berman wrote:
For next release we will review basicHash swapping.  I would like to understand the rationale behind the decision that was made originally not to do it...and what happens (if anything) if we do.
I found this old thread (<a href="http://forum.world.st/identityHash-and-become-question-td1404098.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FidentityHash-and-become-question-td1404098.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHtjzq0jpKWt2ZvMCMxo8vB5jN_AA';return true;">http://forum.world.st/identityHash-and-become-question-td1404098.html) as a start for research.  I don't have much time at the moment to dig deeper, but as I said, it will be revisited.

... It may well be that my changing their identity hashes when I swap them is actually creating problems for me. I'll have to check this out carefully. ...

Well, not swapping the basic hashes definitely breaks their use in hashed collections. It is desirable that the reference held in an identity hashed collection should retain the identity hash it had when it was inserted into the collection.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.