1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 06:41:13 +02:00

deprecate omission of port to ice-9 format

* module/ice-9/format.scm (format): Add port and format-string as formal
  arguments. Seems also to have triggered a reindent.  Formally
  deprecate omitting the port, as it's usually an error.

* test-suite/tests/format.test ("format basic output")
  ("format basic output", "~{ iteration"): Fix up tests that omitted the
  destination port.
This commit is contained in:
Andy Wingo 2010-12-18 12:06:53 +01:00
parent 29d096c8e6
commit 2ce77e6cf6
2 changed files with 72 additions and 53 deletions

View file

@ -44,7 +44,7 @@
;;; End of configuration ----------------------------------------------------
(define (format . args)
(define (format port format-string . args)
(define format:version "3.0")
(define format:port #f) ; curr. format output port
(define format:output-col 0) ; curr. format output tty column
@ -1645,7 +1645,26 @@
(set! format:fn-str (make-string format:fn-max)) ; number buffer
(set! format:en-str (make-string format:en-max)) ; exponent buffer
(apply format:format args))
(apply format:format port format-string args))
(begin-deprecated
(set! format
(let ((format format))
(case-lambda
((port format-string . args)
(if (string? port)
(begin
(issue-deprecation-warning
"Omitting the destination port on a call to format is deprecated."
"Pass #f as the destination port, before the format string.")
(apply format #f port format-string args))
(apply format port format-string args)))
((deprecated-format-string-only)
(issue-deprecation-warning
"Omitting the destination port on a call to format is deprecated."
"Pass #f as the destination port, before the format string.")
(format #f deprecated-format-string-only))))))
;; Thanks to Shuji Narazaki
(module-set! the-root-module 'format format)

View file

@ -26,9 +26,9 @@
(with-test-prefix "format basic output"
(pass-if "format ~% produces a new line"
(string=? (format "~%") "\n"))
(string=? (format #f "~%") "\n"))
(pass-if "format ~& starts a fresh line"
(string=? (format "~&abc~&~&") "abc\n"))
(string=? (format #f "~&abc~&~&") "abc\n"))
(pass-if "format ~& is stateless but works properly across outputs via port-column"
(string=?
(with-output-to-string
@ -39,7 +39,7 @@
(format #t "~&~&")))
"xyz\nabc\n"))
(pass-if "format ~F (format-out-substr) maintains the column correctly"
(= (string-length (format "~@F~20T" 1)) 20)))
(= (string-length (format #f "~@F~20T" 1)) 20)))
;;;
;;; misc
@ -99,4 +99,4 @@
;; In Guile 1.6.4 and earlier, the maximum iterations parameter defaulted
;; to 100, but it's now like Common Lisp where the default is no limit
(pass-if "no arbitrary iteration limit"
(= (string-length (format "~{~a~}" (make-list 200 #\b))) 200)))
(= (string-length (format #f "~{~a~}" (make-list 200 #\b))) 200)))