Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

format ~d, sign and padding

7 views
Skip to first unread message

Christophe Rhodes

unread,
Jul 30, 2001, 7:51:36 AM7/30/01
to
For the call
(format nil "~3,'0@d" 5)
clisp, cmucl (and sbcl) return "0+5", while openmcl gives "+05".

If, as I suspect, openmcl is wrong in this case (though the CLHS isn't
explicit on this, it's rather more explicit in the case of ~@f:
"First, leading copies of the character padchar (which defaults to a
space) are printed, if necessary, to pad the field on the left."), is
there an easy way of obtaining "+05" from 5 via format, or do I have
to break it up into two steps, as in
(let ((x 5)) (format nil "~[-~:;+~]~2,'0d" (signum x) x))? Not that
I'm particularly averse to this, but if there's a ready-made way I
wouldn't mind knowing about it.

Thanks,

Christophe
--
Jesus College, Cambridge, CB5 8BL +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/ (defun pling-dollar
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)

Christophe Rhodes

unread,
Jul 30, 2001, 7:54:20 AM7/30/01
to
[ superseded to fix code example ]

For the call
(format nil "~3,'0@d" 5)
clisp, cmucl (and sbcl) return "0+5", while openmcl gives "+05".

If, as I suspect, openmcl is wrong in this case (though the CLHS isn't
explicit on this, it's rather more explicit in the case of ~@f:
"First, leading copies of the character padchar (which defaults to a
space) are printed, if necessary, to pad the field on the left."), is
there an easy way of obtaining "+05" from 5 via format, or do I have
to break it up into two steps, as in

(let ((x 5)) (format nil "~[-~:;+~]~2,'0d" (1+ (signum x)) x))? Not that

0 new messages