[plt-scheme] Fwd: [Lisp] MzScheme string formatting

From: Paul A. Steckler (stecksoft at gmail.com)
Date: Sat May 24 15:26:34 EDT 2008

Forwarded from the LispNYC list.  I told the poster to try plt-scheme,
but here's his message in case he doesn't.

-- Paul

---------- Forwarded message ----------
From: Arkady Andrukonis <grazingcows at yahoo.com>
Date: Sat, May 24, 2008 at 12:06 PM
Subject: [Lisp] MzScheme string formatting
To: lisp <lisp at lispnyc.org>


Hi,

Does anyone have a reference for MzScheme format
string patterns for formatting decimal output? The
online reference does not seem have the format-string
magic.

(printf format-string input ...) or (format
format-string input ...)

For example,

;; format decimal to 2 places in Java printf("%.2d")
;; MzScheme produces the following
(- 0.9876 0.9865) -> 0.001099999999999899
;; this one does not work
(format "~w,2F~%" (- 0.9876 0.9865)) ; white space not
allowed
;; this is legal Scheme
(format "~8,2F" 1/3) -> "        0.33" ; padded with 8
spaces, not in MzScheme
;; we can print numbers as binary, octal, or
hexadecimal
(printf "#b~b #o~o #b~b ~%" 16 8 2) -> #x10 #o10 #b10
;; or inexact->exact
(inexact->exact (- 0.9876 0.9865)) ->
9907919180215/9007199254740992
;; how about formatting decimals?

Thanks,

RKD



_______________________________________________
Lisp mailing list
Lisp at lispnyc.org
http://www.lispnyc.org:8080/mailman/listinfo/lisp


Posted on the users mailing list.