[Pharo-dev] Transcript and ScaledDecimal Issue

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Nov 19 16:51:29 EST 2013


store: is very old API and its raison d'être is like print: to allow
uninterrupted cascades.

someStream
    nextPut: someChar;
    print: someObject;
    nextPutAll: someString;
    store: someOtherObject.

compared to:

someStream nextPut: someChar.
someObject printOn: someStream.
someStream nextPutAll: someString.
someOtherObject storeOn: someStream.


2013/11/19 Stéphane Ducasse <stephane.ducasse at inria.fr>

> I forgot it because the API of Transcript is totally undefined. I have no
> idea about what store: is about.
> What I wanted is to have a transcript that can be used to understand
> concurrent programming.
>
> Stef
>
> On Nov 18, 2013, at 5:26 PM, phil at highoctane.be wrote:
>
> Sure but still, why isn't store: in the Transcript for these? As they are
> in the other classes
>
>
>
>
>
> On Mon, Nov 18, 2013 at 5:19 PM, Sven Van Caekenberghe <sven at stfx.eu>wrote:
>
>> You could try using #storeString as in
>>
>> Transcript show: (1 / 2) asScaledDecimal storeString
>>
>> Sven
>>
>> On 18 Nov 2013, at 17:09, phil at highoctane.be wrote:
>>
>> > I was playing with ScaledDecimal when doing experiments with numbers in
>> Pharo.
>> >
>> > Now, ScaledDecimal says in its comment:
>> >
>> > "Note that a ScaledDecimal does not printOn: exactly, however it will
>> storeOn: exactly because the full precision fraction is kept in memory."
>> >
>> > This happens to be right when inspecting the expressions.
>> >
>> > Now, I tried to do the following:
>> >
>> > x := 2 asScaledDecimal.
>> > y := 1 asScaledDecimal.
>> >
>> > z := (y / x).
>> >
>> > z storeOn: Transcript.
>> >
>> > And z storeOn: Transcript fails miserably.
>> >
>> > This is due to storeOn: doing:
>> >
>> > storeOn: aStream
>> >       "ScaledDecimal sometimes have more digits than they print
>> (potentially an infinity).
>> >       In this case, do not use printOn: because it would loose some
>> extra digits"
>> >
>> >       self shouldBePrintedAsLiteral
>> >               ifTrue: [self printOn: aStream]
>> >               ifFalse: [aStream
>> >                       nextPut: $(;
>> >                       store: numerator;
>> >                       nextPut: $/;
>> >                       store: denominator;
>> >                       nextPut: $s;
>> >                       store: scale;
>> >                       nextPut: $)]
>> >
>> > And store: doesn't exists in the ThreadSafeTranscript which happens to
>> be no stream at all.
>> >
>> > Try this out:
>> >
>> > x := 2 asScaledDecimal.
>> > y := 1 asScaledDecimal.
>> >
>> > z := (y / x).
>> >
>> > "works"
>> > 5.0 storeOn: Transcript.
>> > Transcript flush.
>> >
>> > "works"
>> > (1/2) storeOn: Transcript.
>> > Transcript flush.
>> >
>> > "fails"
>> > z storeOn: Transcript.
>> > Transcript flush.
>> >
>> > "works"
>> > s := (String new: 30).
>> > st := s writeStream.
>> > z storeOn: st.
>> > Transcript
>> >       show: 'storeOn: ', st contents;
>> >       cr;
>> >       show: z.
>> >
>> > Kind of annoying to do while explaining to kids.
>> >
>> > The ThreadSafe transcript looks like to be subclassed from Object and
>> being no real stream at all.
>> >
>> > Why is it so?
>> >
>> > Phil
>> >
>> >
>> >
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131119/71095c41/attachment-0002.html>


More information about the Pharo-dev mailing list