[squeak-dev] Re: printing literals exactly (was isSelfEvaluating)

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Sat Oct 31 21:11:26 UTC 2009


2009/10/31 Colin Putney <cputney at wiresong.ca>:
>
> On 31-Oct-09, at 9:05 AM, Nicolas Cellier wrote:
>
>> Hehe, I've got a plan.
>>
>> Use storeOn: rather than printOn: to produce the decompileString.
>> It will be the same for all literals, but Float in which I will
>> override storeOn:
>>
>> My plan is to print exactly if isFinite, or invoke a message pattern
>> otherwise (Float nan, Float infinity, Float infinity negated).
>> Note that these exceptional values are not literals (I already fixed
>> that).
>
> And to generalize a bit more, the classes that were implementing
> #isSelfEvaluating could instead override #storeOn: to send #printOn:, and
> get a "prettier" result than the #storeOn: implemented in Object.
>
> Colin
>
>

I think most already do storeOn: pretty well.

{1 at 2. 1->2. 0 at 0 extent: 1 at 1. RunArray new: 5 withAll: #bold} collect:
[:e | String streamContents: [:str | e storeOn: str]].

#('(1 at 2)' '(1->2)' '0 at 0 corner: 1 at 1' '(RunArray runs: #(5 ) values: #(#bold ))')

#storeOn: behaves better than #printOn: w.r.t. parenthesis,
unfortunately not all and that is a bug

{(0 at 0 extent: 1 at 1) -> 0} collect: [:e | String streamContents: [:str |
e storeOn: str]].
 #('(0 at 0 corner: 1 at 1->0)')

Nicolas



More information about the Squeak-dev mailing list