printfの自作
Posted feedbacks - diff
しまった。複数のフォーマット指示子がある場合にちゃんと動きませんでした。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | *** t.scm 2007-11-25 01:51:56.000000000 -1000
--- t2.scm 2007-11-25 01:53:52.000000000 -1000
***************
*** 13,28 ****
(define (pick-arg conv args)
(if (equal? conv "%") (values #f args) (car+cdr args)))
(define (rec fmt args)
! (rxmatch-case fmt
! [#/(.*)%([-+ #0]*)(\d+|\*)?(?:\.(\d*|\*))?([diouxXeEfFgGaAcspn%])(.*)/
! (_ before flags width prec conv after)
! (receive (width args) (get-var-arg 'width width args)
! (receive (prec args) (get-var-arg 'prec prec args)
! (receive (arg args) (pick-arg conv args)
! `(,before
! ,(fill width flags (dispatch arg prec flags conv))
! ,(rec after args)))))]
! [else fmt]))
(define (dispatch arg prec flags conv)
(case (ref conv 0)
[(#\d #\i #\u) (int arg prec flags 10 conv)]
--- 13,31 ----
(define (pick-arg conv args)
(if (equal? conv "%") (values #f args) (car+cdr args)))
(define (rec fmt args)
! (receive (pre post) (string-scan fmt #\% 'both)
! (if post
! (rxmatch-case post
! [#/([-+ #0]*)(\d+|\*)?(?:\.(\d*|\*))?([diouxXeEfFgGaAcspn%])(.*)/
! (_ flags width prec conv after)
! (receive (width args) (get-var-arg 'width width args)
! (receive (prec args) (get-var-arg 'prec prec args)
! (receive (arg args) (pick-arg conv args)
! `(,pre
! ,(fill width flags (dispatch arg prec flags conv))
! ,(rec after args)))))]
! [else (error "bad format string:" fmt)])
! fmt)))
(define (dispatch arg prec flags conv)
(case (ref conv 0)
[(#\d #\i #\u) (int arg prec flags 10 conv)]
|




yappy
#4119()
[
C
]
Rating-2/20=-0.10
Rating-2/20=-0.10-0+
[ reply ]