[squeak-dev] CompiledCode(SequenceableCollection)>>#flatten

Tobias Pape Das.Linux at gmx.de
Thu Dec 30 12:40:53 UTC 2021


Hi

> On 30. Dec 2021, at 13:22, christoph.thiede at student.hpi.uni-potsdam.de wrote:
> 
> Hi all,
> 
> this fails:
> 
>     {Object >> #halt} flatten.

I'd argue that this is ok.
A compiled method is a collection of stuff, mostly bytecode, and also quite special.

If you want to unravel some nested collections with compiled methods inside,
just use #gather: instead.


> 
>     CompiledMethod(Object)>>error:
>         Receiver: (Object>>#halt "a CompiledMethod(343681)")
>         Arguments and temporary variables: 
>             aString:     'subscript is out of bounds: 1'
>         Receiver's instance variables: 
>     (Object>>#halt "a CompiledMethod(343681)")
> 
>     CompiledMethod(Object)>>errorSubscriptBounds:
>         Receiver: (Object>>#halt "a CompiledMethod(343681)")
>         Arguments and temporary variables: 
>             index:     1
>         Receiver's instance variables: 
>     (Object>>#halt "a CompiledMethod(343681)")
> 
>     CompiledMethod(Object)>>at:
>         Receiver: (Object>>#halt "a CompiledMethod(343681)")
>         Arguments and temporary variables: 
>             index:     1
>         Receiver's instance variables: 
>     (Object>>#halt "a CompiledMethod(343681)")
> 
>     CompiledMethod(SequenceableCollection)>>do:
>         Receiver: (Object>>#halt "a CompiledMethod(343681)")
>         Arguments and temporary variables: 
>             aBlock:     [closure] in [] in CompiledMethod(SequenceableCollection)>>flatten
>             index:     1
>             indexLimiT:     48
>         Receiver's instance variables: 
>     (Object>>#halt "a CompiledMethod(343681)")
> 
>     [] in CompiledMethod(SequenceableCollection)>>flatten
>         Receiver: (Object>>#halt "a CompiledMethod(343681)")
>         Arguments and temporary variables: 
>             stream:     a WriteStream
>         Receiver's instance variables: 
>     (Object>>#halt "a CompiledMethod(343681)")
> 
> You get the problem, we don't want to split up compiled codes. How should we fix it? 

Not. It's an annoyance, yes, but not a problem per se, I'd say.

> Replace each isString with something like each canBeFlattened? Or just override #flatten on String and CompiledCode instead?
> 

no.

> By the way, I am also not sure whether this is what we expect:
> 
>     {'foo'. 'bar' asText. UUID new} flatten. "#('foo' $b $a $r 188 125 70 227 253 103 13 67 180 100 32 52 18 134 92 153)"
> 

It really depends on what you expect. The text-vs-string thing is unfortunate and needs being looked into, yes. but For UUID, some might want it flattened, some not.
I presume you see a uuid as something atomic, scalar, while others do not.

> 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 ... :-)
> 

This makes me think copying over #flatten from other languages was an error.
If in doubt, use #gather: which is much more mature.

Best regards
	-Tobias

> Best,
> Christoph
> 
> ---
> Sent from Squeak Inbox Talk




More information about the Squeak-dev mailing list