[Pharo-dev] Transcript and ScaledDecimal Issue

Sven Van Caekenberghe sven at stfx.eu
Mon Nov 18 12:36:57 EST 2013


On 18 Nov 2013, at 17:26, phil at highoctane.be wrote:

> Sure but still, why isn't store: in the Transcript for these? As they are in the other classes 

I am not sure the #storeOn: mechanism is still very relevant, it is a very simple form of serialization. There are multiple alternatives today (Fuel, JSON, STON, …).

Another point is that what people call ’the Stream API’ is very/too wide, hindering composition, wrapping and alternative implementations - hence Xtreams.

Adding the missing #store: would not be much work, but would it ever be used for real ?   

> 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
> >
> >
> >
> 
> 
> 





More information about the Pharo-dev mailing list