<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr">Hi Christoph,<div dir="ltr"><br><blockquote type="cite">On Dec 30, 2021, at 4:23 AM, Christoph.Thiede@student.hpi.uni-potsdam.de wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">Hi all,<br>
<br>
this fails:<br>
<br>
    <font color="#000000">{</font><font color="#000000">Object</font><font color="#000000"> </font><font color="#000080">>></font><font color="#000000"> </font><font color="#000080">#halt</font><font color="#000000">}</font><font color="#000000"> </font><font color="#000080">flatten</font><font color="#000000">.</font><br>
<br>
<font color="#808080">    CompiledMethod(Object)>>error:<br>
        Receiver: (Object>>#halt "a CompiledMethod(343681)")<br>
        Arguments and temporary variables: <br>
            aString:     'subscript is out of bounds: 1'<br>
        Receiver's instance variables: <br>
    (Object>>#halt "a CompiledMethod(343681)")<br>
<br>
    CompiledMethod(Object)>>errorSubscriptBounds:<br>
        Receiver: (Object>>#halt "a CompiledMethod(343681)")<br>
        Arguments and temporary variables: <br>
            index:     1<br>
        Receiver's instance variables: <br>
    (Object>>#halt "a CompiledMethod(343681)")<br>
<br>
    CompiledMethod(Object)>>at:<br>
        Receiver: (Object>>#halt "a CompiledMethod(343681)")<br>
        Arguments and temporary variables: <br>
            index:     1<br>
        Receiver's instance variables: <br>
    (Object>>#halt "a CompiledMethod(343681)")<br>
<br>
    CompiledMethod(SequenceableCollection)>>do:<br>
        Receiver: (Object>>#halt "a CompiledMethod(343681)")<br>
        Arguments and temporary variables: <br>
            aBlock:     [closure] in [] in CompiledMethod(SequenceableCollection)>>flatten<br>
            index:     1<br>
            indexLimiT:     48<br>
        Receiver's instance variables: <br>
    (Object>>#halt "a CompiledMethod(343681)")<br>
<br>
    [] in CompiledMethod(SequenceableCollection)>>flatten<br>
        Receiver: (Object>>#halt "a CompiledMethod(343681)")<br>
        Arguments and temporary variables: <br>
            stream:     a WriteStream<br>
        Receiver's instance variables: <br>
    (Object>>#halt "a CompiledMethod(343681)")</font><br>
<br>
You get the problem, we don't want to split up compiled codes. How should we fix it? </div></blockquote><div><br></div>I can think of one of two rational ways. The key issue is that a CompiledCode is two sequenceable collections (& a header and trailer), inheriting from ByteArray simply for implementation convenience, and hence do: is not well defined.<div><br></div><div>So one approach would be to implement CompiledCode>>#do: as self shouldNotImplement with an explanatory comment, stating that at: accesses bytecodes, and literalsDo: should be used to enumerate literals.  I’d also implement bytecodesDo: to complement literalsDo:.</div><div><br></div><div>The second approach would be to define CompiledCode>>#do: to enumerate over bytecodes.</div><div><br></div><div><blockquote type="cite">Replace <font color="#000080"><font face="Bitmap DejaVu Sans" size="9">each</font></font><font color="#000000"><font face="Bitmap DejaVu Sans" size="9"> </font></font><font color="#000080"><font face="Bitmap DejaVu Sans" size="9">isString</font></font> with something like <font color="#000080">each</font><font color="#000000"> </font><font color="#FF0000">canBeFlattened</font>? Or just override <font color="#000080">#flatten</font> on String and CompiledCode instead?<br></blockquote><div><br></div>This is a poor approach because it introduces special cases rather than dealing with the underlying issue.</div><div><br><blockquote type="cite"><div dir="ltr">
<br>
By the way, I am also not sure whether this is what we expect:<br>
<br>
    <font color="#000000">{</font><font color="#800080">'foo'</font><font color="#000000">.</font><font color="#000000"> </font><font color="#800080">'bar'</font><font color="#000000"> </font><font color="#000080">asText</font><font color="#000000">.</font><font color="#000000"> </font><font color="#000000">UUID</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000">}</font><font color="#000000"> </font><font color="#000080">flatten</font><font color="#000000">.</font><font color="#000000"> </font><font color="#008080">"#('foo' $b $a $r 188 125 70 227 253 103 13 67 180 100 32 52 18 134 92 153)"</font><br>
<br>
Maybe also override #flatten on Text and UUID? Any other collections that we do not want to flatten? It is hard to make this decision without knowledge about the domain-specific context ... <i>:-)</i><br></div></blockquote><div><br></div>KISS.  Strings and UUIDs ate collections so flatten: does the non-magic but predictable thing and indeed answers</div><div><br></div><div> <font color="#000000">{</font><font color="#800080">'foo'</font><font color="#000000">.</font><font color="#000000"> </font><font color="#800080">'bar'</font><font color="#000000"> </font><font color="#000080">asText</font><font color="#000000">.</font><font color="#000000"> </font><font color="#000000">UUID</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000">}</font><font color="#000000"> </font><font color="#000080">flatten</font><font color="#000000">.</font><font color="#000000"></font><font color="#008080">"#('foo' $b $a $r 188 125 70 227 253 103 13 67 180 100 32 52 18 134 92 153)"</font></div><div><font color="#008080"><span style="caret-color: rgb(0, 128, 128);"><br></span></font></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b">If you want something clever introduce (in your own experimental package first) some variant, fooFlatten: that does what you want.  eg</font></span></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b">      flattenWhen: aBlock</font></span></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b">      flattenUnless: aBlock</font></span></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b"><br></font></span></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b">so eg</font></span></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b">    </font></span><font color="#000000">{</font><font color="#800080">'foo'</font><font color="#000000">.</font><font color="#000000"> </font><font color="#800080">'bar'</font><font color="#000000"> </font><font color="#000080">asText</font><font color="#000000">.</font><font color="#000000"> </font><font color="#000000">UUID</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000">}</font></div><div><font color="#000000">        flattenUnless: [:e| e isString]</font></div><div><span style="caret-color: rgb(0, 128, 128);"><font color="#11053b"><br></font></span><blockquote type="cite"><div dir="ltr">
<br>
Best,<br>
Christoph<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><span></span><br></div></blockquote><br><div>Eliot</div><div>_,,,^..^,,,_ (phone)</div></div></div></body></html>