Add writeln and println functions to complement displayln
This commit is contained in:
parent
bc6670c8e0
commit
62e52bf41d
|
@ -65,12 +65,29 @@ conventions should be assumed for @racket[print], so that environments
|
|||
are free to modify the actual output generated by @racket[print] in
|
||||
any way.}
|
||||
|
||||
@defproc[(writeln [datum any/c] [out output-port? (current-output-port)])
|
||||
void?]{
|
||||
|
||||
The same as @racket[(write datum out)] followed by @racket[(newline out)].}
|
||||
|
||||
@defproc[(displayln [datum any/c] [out output-port? (current-output-port)])
|
||||
void?]{
|
||||
|
||||
The same as @racket[(display datum out)] followed by @racket[(newline out)],
|
||||
which is similar to @as-index{@tt{println}} in Pascal or Java.}
|
||||
which is similar to @tt{println} in Pascal or Java.}
|
||||
|
||||
@defproc[(println [datum any/c] [out output-port? (current-output-port)]
|
||||
[quote-depth (or/c 0 1) 0])
|
||||
void?]{
|
||||
|
||||
The same as @racket[(print datum out quote-depth)] followed by
|
||||
@racket[(newline out)].
|
||||
|
||||
This is not equivalent to @tt{println} in other languages because, by default,
|
||||
it uses the printing conventions of @racket[write]. For a closer analog, use
|
||||
@racket[displayln] instead.}
|
||||
|
||||
@history[#:changed "6.1.1.8" @elem{Added @racket[writeln] and @racket[displayln].}]
|
||||
|
||||
@defproc[(fprintf [out output-port?] [form string?] [v any/c] ...) void?]{
|
||||
|
||||
|
|
|
@ -174,6 +174,15 @@
|
|||
|
||||
(define (port? x) (or (input-port? x) (output-port? x)))
|
||||
|
||||
(define writeln
|
||||
(case-lambda
|
||||
[(v) (writeln v (current-output-port))]
|
||||
[(v p)
|
||||
(unless (output-port? p)
|
||||
(raise-argument-error 'writeln "output-port?" 1 v p))
|
||||
(write v p)
|
||||
(newline p)]))
|
||||
|
||||
(define displayln
|
||||
(case-lambda
|
||||
[(v) (displayln v (current-output-port))]
|
||||
|
@ -182,6 +191,18 @@
|
|||
(raise-argument-error 'displayln "output-port?" 1 v p))
|
||||
(display v p)
|
||||
(newline p)]))
|
||||
|
||||
(define println
|
||||
(case-lambda
|
||||
[(v) (println v (current-output-port) 0)]
|
||||
[(v p) (println v p 0)]
|
||||
[(v p d)
|
||||
(unless (output-port? p)
|
||||
(raise-argument-error 'println "output-port?" 1 v p d))
|
||||
(unless (and (number? d) (or (= 0 d) (= d 1)))
|
||||
(raise-argument-error 'println "(or/c 0 1)" 2 v p d))
|
||||
(print v p d)
|
||||
(newline p)]))
|
||||
|
||||
;; -------------------------------------------------------------------------
|
||||
|
||||
|
@ -232,7 +253,7 @@
|
|||
path-list-string->path-list find-executable-path
|
||||
collection-path collection-file-path load/use-compiled
|
||||
guard-evt channel-get channel-try-get channel-put
|
||||
port? displayln
|
||||
port? writeln displayln println
|
||||
find-library-collection-paths
|
||||
find-library-collection-links
|
||||
bytes-environment-variable-name?
|
||||
|
|
Loading…
Reference in New Issue
Block a user