[racket] ~r behavior with respect to the sign

From: Dmitry Pavlov (dpavlov at ipa.nw.ru)
Date: Tue Jan 14 07:27:36 EST 2014

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.

RACKET TEAM DO YOU HEAR ME


Best regards,

Dmitry


Posted on the users mailing list.