[racket] ~r behavior with respect to the sign

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Tue Jan 14 15:13:12 EST 2014

On 01/14/2014 07:27 AM, Dmitry Pavlov wrote:
> Pierpaolo,
>
> Thank you for your answer, and sorry for the late reply.
>
>>> It seems that ~r formatting function, when given a negative
>>> number and a #:min-width argument, does not treat the "-"
>>> character as part of the number bound by #:min-width,
>>> and moreover, it detaches the "-" from the number:
>>
>> Use srfi/48,  instead.
>
> srfi/48 has a bug which has not been fixed for quite a long time:
> http://bugs.racket-lang.org/query/?cmd=view%20audit-trail&database=default&pr=12579
>
> (I just tested it on 5.90.0.6 -- it is still there)
>
>
>> Also look at this previous discussion:
>> https://groups.google.com/forum/#!topic/racket-users/l5-WYsCnSJc
>
> Your suggestion with aligning via ~a is interesting, thanks!
> I would add, though, that #:min-width is more preferable that #:width
> because it allows numbers that are too big for the specified
> width still be displayed.
>
>  >  (~a (~r -123456789.12 #:precision 6) #:width 8 #:align 'right)
> "-1234567"
>  >  (~a (~r -123456789.12 #:precision 6) #:min-width 8 #:align 'right)
> "-123456789.12"
>
>
> Anyway, who on Earth needs the detached "-" that ~r produces?
> To me, it seems most logical to ask Racket team to change or
> extend ~r, because most people who use formatted output of
> numbers would expect "-" attached to the number.

The behavior is intentional, because you can change the padding 
character, and "-  123" seems more useful (for blank padding) than 
"00-123" (for 0 padding).

If you (or anyone else) would like to add more padding options that acts 
like the combination of ~a and ~r above, that would be fine with me. I 
don't have time to work on the code right now, but I'll take patches or 
pull requests.

Ryan


Posted on the users mailing list.