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=== _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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=== _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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=== > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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=== _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
On Thu, 26 Jul 2007 14:43:41 -0700, Bert Freudenberg
<[hidden email]> 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. Well, y'all can go to town modifying whatever. I was simply asking for you provided here. That's why I asked on the noob list. Thanx. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
On Thu, 26 Jul 2007 15:03:36 -0700, Bert Freudenberg
<[hidden email]> wrote: > 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. That's cool but I'm basically using the Fractions class for quick double-checks of math with fractions, so I sit down at whatever machine is handy, pull up Squeak and... (Not that I'd object to printOn being changed or anything; it's just overkill.) _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Thu, 26 Jul 2007 18:01:37 -0700, Blake <[hidden email]> wrote:
>> 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. > > That's cool but I'm basically using the Fractions class for quick > double-checks of math with fractions, so I sit down at whatever machine > is handy, pull up Squeak and... > > (Not that I'd object to printOn being changed or anything; it's just > overkill.) (Though I admit I put this in one of my images.) _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Blake-5
Hi, I don't know why you say that is odd because this doesn't exist in the core of Java, C++, and C to name a few. Also, if you need to redefine things within your image, it's very easy to do so and I agree with the responses of both Nicolas and Bert. In short, this and other Smalltalk environment provide a solid framework of classes for one to easily extend.
Good luck, -Conrad
On 7/25/07, Blake <
[hidden email]> wrote: Hey, guys: _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Thu, 26 Jul 2007 22:43:18 -0700, Conrad Taylor <[hidden email]>
wrote: > Hi, I don't know why you say that is odd because this doesn't exist in > the core of Java, C++, and C to name a few. Also, if you need to > redefine > things within your image, it's very easy to do so and I agree with the > responses of both Nicolas and Bert. In short, this and other Smalltalk > environment provide a solid framework of classes for one to easily > extend. Well, first of all, it's odd because it's wrong. Bert showed a perfectly good way to do what I want. Second of all, I wouldn't deign to compare Squeak to those other, lesser languages. ;-) _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi, please explain why it's wrong when one can define their own method to print an instance of a class. Second, a
fraction is the ratio of two whole numbers, or to put it simply, one whole number divided by another whole number. Thus, the implementation of class Fraction is in sync with the definition.
-Conrad On 7/26/07, Blake <[hidden email]> wrote: On Thu, 26 Jul 2007 22:43:18 -0700, Conrad Taylor <[hidden email]> _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Fri, 27 Jul 2007 00:17:12 -0700, Conrad Taylor <[hidden email]>
wrote: > Hi, please explain why it's wrong when one can define their own method to > print an instance of a class. Second, a fraction is the ratio of two > whole numbers, or to put it simply, one whole number divided by another > whole > number. Thus, the implementation of class Fraction is in sync with the > definition. OK, language barrier: I said "I find it odd that class (A) doesn't do (B)". I wrote that fully believing that class (A) =did= do (B) and I just couldn't see it. In other words, I wrote the statement outline the "oddity" expecting to be corrected, and I was. It would indeed have been odd for a seasoned Smalltalk like Squeak aimed heavily at education/math/science targets to not provide a simple way to do something everyone working with fractions for educational purposes would eventually need. That's all. ===Blake=== _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Blake-5
> Hey, guys:
> > (And who came up with that whole "improper" terminology? Some guys with > small numerators, I'd bet....) > > ===Blake=== I spent many years teaching remedial maths. The whole proper/improper/mixed number concept messes with many kids learning arithmetic with fractions. As I recall, proper fractions used to be written as a sum of partial fractions with numerator 1. For example: 3/8 = 1/4 + 1/8 so it was written as a proper fraction as 1 1 - - 4 8 2/5 = 1/4 + 1/10 + 1/20 1 1 1 - - - 4 10 20 12/7 = 1 + 1/2 + 1/3 + 1/42 1 1 1 1 - - - (a mixed number) 2 3 42 If it was clear from context that a fraction was being discussed it would be written just by listing the denominators: 1 2 3 42 This caused much confusion, is 2 4 3/4 or 9/4 (i.e. a mixed number or a proper fraction)? 2 2 4 was always 11/4 though (as the second 2 had to denote 1/2). A fraction written any other way (excepting continued fractions) was considered 'improper'. Later usage allowed for larger numerators. Improper fractions were then fractions where the numerator was larger than the denominator, as we use today. Proper fractions are always < 1. 1 3/4 as meaning 7/4 is called a mixed number, and use of mixed numbers is a cause for many errors, as if written messily it can easily be read as 13/4 or even 1/14. To my mind a class that displays as a mixed number should be a subclass of Fraction, as the default of displaying a fraction as an improper fraction has no room for ambiguity. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi, I agree with you 100% in this regard because I have arrived at the
same conclusion. Thus, a better way to extend the image to support mixed-numbers would be to create a class called MixedFraction which is subclassed from Fraction. -Conrad On 7/27/07, [hidden email] <[hidden email]> wrote: > > Hey, guys: > > > > (And who came up with that whole "improper" terminology? Some guys with > > small numerators, I'd bet....) > > > > ===Blake=== > > I spent many years teaching remedial maths. The whole > proper/improper/mixed number concept messes with many kids learning > arithmetic with fractions. > > As I recall, proper fractions used to be written as a sum of partial > fractions with numerator 1. For example: > > 3/8 = 1/4 + 1/8 so it was written as a proper fraction as > > 1 1 > - - > 4 8 > > 2/5 = 1/4 + 1/10 + 1/20 > > 1 1 1 > - - - > 4 10 20 > > 12/7 = 1 + 1/2 + 1/3 + 1/42 > > 1 1 1 > 1 - - - (a mixed number) > 2 3 42 > > If it was clear from context that a fraction was being discussed it would > be written just by listing the denominators: > > 1 2 3 42 > > This caused much confusion, is 2 4 3/4 or 9/4 (i.e. a mixed number or a > proper fraction)? > > 2 2 4 was always 11/4 though (as the second 2 had to denote 1/2). > > A fraction written any other way (excepting continued fractions) was > considered 'improper'. > > Later usage allowed for larger numerators. Improper fractions were then > fractions where the numerator was larger than the denominator, as we use > today. Proper fractions are always < 1. > > 1 3/4 as meaning 7/4 is called a mixed number, and use of mixed numbers is > a cause for many errors, as if written messily it can easily be read as > 13/4 or even 1/14. > > To my mind a class that displays as a mixed number should be a subclass of > Fraction, as the default of displaying a fraction as an improper fraction > has no room for ambiguity. > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |