[Newbies] Re: Proper fractions?
Bert Freudenberg
bert at freudenbergs.de
Thu Jul 26 22:03:36 UTC 2007
Blake, if you actually want to make this work in your image, you
could do this:
Fraction>>printOn: aStream base: base
| int |
(int := self integerPart) = 0
ifTrue: [aStream nextPut: $(.
numerator printOn: aStream base: base.
aStream nextPut: $/.
denominator printOn: aStream base: base.
aStream nextPut: $)]
ifFalse: [aStream nextPut: $(.
int printOn: aStream base: base.
aStream nextPut: $+.
self fractionPart printOn: aStream base: base.
aStream nextPut: $)]
(and delete Fraction>>printOn: which os redundant anyway)
I can see how this would be helpful in debugging if you deal with
fractions a lot.
- Bert -
On Jul 26, 2007, at 23:43 , Bert Freudenberg wrote:
> This would work:
>
> | x |
> x := 4/3.
> '(', x integerPart printString, '+', x fractionPart printString, ')'
>
> and also would have the property of being self-evaluating just like
> fractions did before.
>
> Though I agree with Nic that this is not what I'd want to see by
> default.
>
> - Bert -
>
> On Jul 26, 2007, at 23:17 , nicolas cellier wrote:
>
>> Can the system come pre-programmed with every possible wish of
>> every client for every domain?
>>
>> Propose your extensions, if use is sufficiently wide, they can
>> eventually be adopted in an official image.
>>
>> I'm not sure this one will. It makes sense to you because the
>> fraction denominator is small, a rather ideal case (the quotations
>> case i guess) which does have full generallity.
>>
>> Could you tell me what is 3 (39854788871587/281474976710656)?
>>
>> We have plenty over ways to write fractions (continuous fraction
>> expansion would be one) depending on the domain we are operating...
>> Beside, since integerPart and fractionPart exists, extending is
>> cheap.
>>
>> Nicolas
>>
>> Blake a écrit :
>>> Hey, guys:
>>> Any way to make the fraction class print itself out with its
>>> integer part separate from its fractional part. In other words,
>>> if I have
>>> 4/3
>>> (an "improper" fraction) can I make it print out as:
>>> 1 1/3
>>> ? I mean, I know I can write a routine that does this but it
>>> seemed odd to me that one doesn't exist.
>>> (And who came up with that whole "improper" terminology? Some
>>> guys with small numerators, I'd bet....)
>>> ===Blake===
More information about the Beginners
mailing list