Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Status: FixProposed
Owner: [hidden email]
Labels: Milestone-1.4

New issue 4909 by [hidden email]: Fraction readFromString: '1/2'  
---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

On both Squeak 3.9 (I supose others too) and Pharo:
Fraction readFromString: '1/2'  ---> 1
'1/2' asNumber ---> 1

fix

Number #readFrom: stringOrStream
     "Answer a number as described on aStream.  The number may
     include a leading radix specification, as in 16rFADE"
     | value base aStream sign |
     aStream _ (stringOrStream isString)
         ifTrue: [ReadStream on: stringOrStream]
         ifFalse: [stringOrStream].
     (aStream nextMatchAll: 'NaN') ifTrue: [^ Float nan].
     sign _ (aStream peekFor: $-) ifTrue: [-1] ifFalse: [1].
     (aStream nextMatchAll: 'Infinity') ifTrue: [^ Float infinity * sign].
     base _ 10.
     value _ Integer readFrom: aStream base: base.
"this line "
     (aStream peekFor: $/) ifTrue:[^Fraction    numerator: value  
denominator: (aStream upTo: $\) asInteger].
"  added "
     (aStream peekFor: $r)

         ifTrue:
             ["<base>r<integer>"
             (base _ value) < 2 ifTrue: [^self error: 'Invalid radix'].
             (aStream peekFor: $-) ifTrue: [sign _ sign negated].
             value _ Integer readFrom: aStream base: base].
     ^ self readRemainderOf: value from: aStream base: base withSign: sign.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo

Comment #1 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

See also http://bugs.squeak.org/view.php?id=3712

Implementing it also raise some questions... what do you expect from this  
one:

(Number readFrom: '13/10/2011')

Shall readFrom: read one occurrence and leave the stream positionned for  
the next one?
Or shall it fail in case of extra characters?

Nicolas


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Updates:
        Status: ReviewNeeded

Comment #2 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Updates:
        Status: Accepted

Comment #3 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

I'm afraid the fix cause more problems than solutions. I don't know what is  
happening, and I couldn't go deep, but many things are working bad.
So I have to implement temporarily String #asFraction to fullfill my  
requirements.


Yes, the interaction between fractions and strings is not good.  For  
instance:
    Fraction readFromString: ((1/2) printString)
raises an error, because printing fractions puts parenthesis around
the fraction, and that just isn't a valid number.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Updates:
        Labels: Type-Bug

Comment #4 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Updates:
        Status: FixReviewNeeded

Comment #5 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

Name: SLICE-Issue-4909--Fraction-readFromString-nice.1
Author: nice
Time: 30 October 2011, 5:00:59 pm
UUID: d9b65b73-fc50-40a2-b274-648b1b6ed6a4
Ancestors:
Dependencies: Kernel-nice.959, KernelTests-nice.363

Here is a restricted implementation (with tests) which
- does not handle parenthesis
- does not handle spaces
- does not modify Number class>>readFrom:

Number readFrom: '1/2' --> 1
Fraction readFrom: '1/2' --> 1/2


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 4909 in pharo: Fraction readFromString: '1/2' ---> 1

pharo
Updates:
        Status: Closed

Comment #6 on issue 4909 by [hidden email]: Fraction  
readFromString: '1/2'  ---> 1
http://code.google.com/p/pharo/issues/detail?id=4909

in 14220


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker