<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p>> <span>Well, that won't work with the primitive, right?</span></p>
<p><br>
</p>
<p>The primitive appears only to work for two objects of equal class & lengths, or am I wrong?</p>
<p><br>
</p>
<p>If you do</p>
<p><br>
</p>
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p></p>
<div>c1 := Object newUniqueClassInstVars: 'foo bar' classInstVars: ''.</div>
<div>c2 := Object newUniqueClassInstVars: 'bar foo' classInstVars: ''.</div>
<div>o1 := c1 new</div>
<div><span style="white-space:pre"></span>instVarNamed: #foo put: 6;</div>
<div><span style="white-space:pre"></span>instVarNamed: #bar put: 7;</div>
<div><span style="white-space:pre"></span>yourself.</div>
<div>o2 := c1 new.</div>
<div>o2 copyFrom: o1.</div>
<div>o2 instVarAt: 1 "6".</div>
<br>
<p></p>
</div>
</blockquote>
<div style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p>(using my proposed implementation),</p>
<p>the primitive will do its job ...</p>
<p><br>
</p>
<p>Best,</p>
<p>Christoph</p>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Tobias Pape <Das.Linux@gmx.de><br>
<b>Gesendet:</b> Samstag, 4. Januar 2020 17:07 Uhr<br>
<b>An:</b> The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] Object >> #copyFrom: vs Object >> #copySameFrom:</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
> On 04.01.2020, at 16:03, Thiede, Christoph <Christoph.Thiede@student.hpi.uni-potsdam.de> wrote:<br>
> <br>
> Hi Levente,<br>
> <br>
> yes, that would look more intuitive for me. Why else should any of these methods ask for #allInstVarNames?<br>
> <br>
> I would like to propose something like this:<br>
> <br>
> copyFrom: anotherObject<br>
> "Copy to myself all instance variables I have in common with anotherObject.  This is dangerous because it ignores an object's control over its own inst vars.  "<br>
> <br>
> | otherInstVars |<br>
> <primitive: 168><br>
> otherInstVars := (anotherObject class allInstVarNames<br>
> withIndexCollect: [:name :index | name -> (anotherObject instVarAt: index)])<br>
> as: Dictionary.<br>
> self class allInstVarNames withIndexDo: [:name :index |<br>
> otherInstVars at: name ifPresent: [:value |<br>
> self instVarAt: index put: value]].<br>
> (self class isVariable and: [anotherObject class isVariable]) ifTrue: [<br>
> 1 to: (self basicSize min: anotherObject basicSize) do: [:ind |<br>
> self basicAt: ind put: (anotherObject basicAt: ind)]].<br>
> <br>
<br>
Well, that won't work with the primitive, right?<br>
-t<br>
<br>
> Best,<br>
> Christoph<br>
> <br>
> Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves@caesar.elte.hu><br>
> Gesendet: Samstag, 4. Januar 2020 04:34 Uhr<br>
> An: The general-purpose Squeak developers list<br>
> Betreff: Re: [squeak-dev] Object >> #copyFrom: vs Object >> #copySameFrom:<br>
>  <br>
> Hi Christoph,<br>
> <br>
> On Sat, 4 Jan 2020, Thiede, Christoph wrote:<br>
> <br>
> > <br>
> > Hi Levente, thanks for the feedback.<br>
> > <br>
> > <br>
> > > What's your use-case?<br>
> > Actually not a real use case, I was just confused by the confusion of both methods.<br>
> > <br>
> > But I would find it cool if my first code example would work, for the best support of converting arbitrary objects between each other.<br>
> <br>
> It's not clear to me what the expected result of your first example is. Is <br>
> it that instance variables are copied by name?<br>
> <br>
> <br>
> Levente<br>
> <br>
> > <br>
> > Best,<br>
> > Christoph<br>
> > <br>
> > _________________________________________________________________________________________________________________________________________________________________________________________________________________________________<br>
> > Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves@caesar.elte.hu><br>
> > Gesendet: Freitag, 3. Januar 2020 23:14:07<br>
> > An: The general-purpose Squeak developers list<br>
> > Betreff: Re: [squeak-dev] Object >> #copyFrom: vs Object >> #copySameFrom:  <br>
> > Hi Christoph,<br>
> > <br>
> > On Fri, 3 Jan 2020, Thiede, Christoph wrote:<br>
> > <br>
> > ><br>
> > > Hi Levente,<br>
> > ><br>
> > ><br>
> > > I don't get that.<br>
> > ><br>
> > ><br>
> > > Did I interpret your explanation correctly?<br>
> > <br>
> > Yes, you did. I just checked why it doesn't work, and it turned out I<br>
> > misremembered how it actually works.<br>
> > The primitive's comment is:<br>
> > <br>
> >          Copy the state of the receiver from the argument.<br>
> >                  Fail if receiver and argument are of a different class.<br>
> >                  Fail if the receiver or argument are contexts (because of context-to-stack mapping).<br>
> >                  Fail if receiver and argument have different lengths (for indexable objects).<br>
> >                  Fail if the objects are not in a fit state to be copied (e.g. married contexts and Cogged methods<br>
> > <br>
> > So, it'll fail, because the classes are not the same (an artifical<br>
> > limitation IMO).<br>
> > The fallback code will only copy slots of the same index if they have the<br>
> > same name (also an artificial limitation).<br>
> > <br>
> > What's your use-case?<br>
> > <br>
> > <br>
> > Levente<br>
> > <br>
> > ><br>
> > ><br>
> > >       fooClass := Object newUniqueClassInstVars: 'a b' classInstVars: ''.<br>
> > > barClass := Object newUniqueClassInstVars: 'b c' classInstVars: ''.<br>
> > > foo := fooClass new.<br>
> > > bar := barClass new<br>
> > > instVarNamed: #b put: 2;<br>
> > > instVarNamed: #c put: 3;<br>
> > > yourself.<br>
> > > foo copyFrom: bar.<br>
> > > foo instVarNamed: #b "expected: 2, actual: nil"<br>
> > ><br>
> > ><br>
> > > Otherwise, if I put #b as the first instvar in both classes, #copyFrom: and #copySameFrom: won't differ again ...<br>
> > ><br>
> > ><br>
> > > Best,<br>
> > ><br>
> > > Christoph<br>
> > ><br>
> > ><br>
> > >________________________________________________________________________________________________________________________________________________________________________________________________________________________________<br>
> > _<br>
> > > Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves@caesar.elte.hu><br>
> > > Gesendet: Freitag, 3. Januar 2020 19:05 Uhr<br>
> > > An: The general-purpose Squeak developers list<br>
> > > Betreff: Re: [squeak-dev] Object >> #copyFrom: vs Object >> #copySameFrom: 
<br>
> > > Hi Christoph,<br>
> > ><br>
> > > The two methods are different. #copyFrom: copies variables by index while<br>
> > > #copySameFrom: copies variables by name.<br>
> > > So, if you have an object named foo of class Foo with 2 instance variables<br>
> > > a and b, and an object named bar of class Bar with 2 instance variables b<br>
> > > and c, then foo copyFrom: bar will copy bar's b to foo's a, and bar's c to<br>
> > > foo's b. #copySameFrom: will copy bar's b to foo's b and leave foo's a as<br>
> > > is.<br>
> > ><br>
> > > Levente<br>
> > ><br>
> > ><br>
> > > On Fri, 3 Jan 2020, Thiede, Christoph wrote:<br>
> > ><br>
> > > ><br>
> > > > Hi all,<br>
> > > ><br>
> > > ><br>
> > > > I don't get the actual difference between #copyFrom: and #copySameFrom:.<br>
> > > ><br>
> > > ><br>
> > > > The latter looks more "modern" to me, as it uses a primitive and has several implementors.<br>
> > > ><br>
> > > > In my opinion, none of them actually matches its description ("Copy to myself all instance variables [named the same in | I have in common with] otherObject"). The following leaves o2 empty:<br>
> > > ><br>
> > > ><br>
> > > > c1 := Object newUniqueClassInstVars: 'foo bar' classInstVars: ''.<br>
> > > > c2 := Object newUniqueClassInstVars: 'bar foo' classInstVars: ''.<br>
> > > > o1 := c1 new<br>
> > > > instVarNamed: #foo put: 6;<br>
> > > > instVarNamed: #bar put: 7.<br>
> > > > o2 := o1 as: c2.<br>
> > > > o2 instVarAt: 1 "nil".<br>
> > > ><br>
> > > > o2 copySameFrom: o1.<br>
> > > > o2 instVarAt: 1 "nil".<br>
> > > ><br>
> > > ><br>
> > > > Question: Could we deprecate #copySameFrom:, and in #copyFrom:, copy *all* matching instvars without respecting their order? Or did I miss any intended difference in behavior?<br>
> > > ><br>
> > > > Best,<br>
> > > > Christoph<br>
> > > ><br>
> > > ><br>
> > > ><br>
> > ><br>
> > ><br>
> > <br>
> ><br>
<br>
<br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>