Add print-value-columns parameter.

This commit is contained in:
Mike Sperber 2021-04-02 14:44:51 +02:00 committed by Matthew Flatt
parent 548aca02e7
commit 922bab40b5
4 changed files with 37 additions and 0 deletions
pkgs
racket-doc/scribblings/reference
racket-test/tests/racket
racket/collects/racket/private

View File

@ -272,6 +272,16 @@ A @tech{parameter} that controls printing of @tech{syntax objects}. Up to
object within @litchar{#<syntax}...@litchar{>} (after the
@tech{syntax object}'s source location, if any).}
@defparam[print-value-columns columns (or/c +inf.0 (and/c exact-integer? (>/c 5)))]{
A @tech{parameter} that contains a recommendation for the number of
columns that should be used for printing values via @racket[print].
May or may not be respected by @racket[print] - the current default
handler for @racket[print] does not. It is expected that REPLs that use
some form of pretty-printing for values respect this parameter.
@history[#:added "8.0.0.13"]
}
@defparam*[current-write-relative-directory path
(or/c (and/c path-string? complete-path?)

View File

@ -0,0 +1,11 @@
#lang racket/base
(require rackunit)
(check-equal? (parameterize ((print-value-columns 10))
(print-value-columns))
10)
(check-equal? (parameterize ((print-value-columns +inf.0))
(print-value-columns))
+inf.0)
(check-exn exn:fail? (lambda () (print-value-columns -5)))
(check-exn exn:fail? (lambda () (print-value-columns 'wrong)))

View File

@ -12,6 +12,7 @@
"cert.rkt"
"submodule.rkt"
"generic-interfaces.rkt"
"print-value-columns.rkt"
"kw-syntax-binding.rkt" ; shadows `syntax-binding-set-extend`
"kw-syntax-serialize.rkt" ; shadows `syntax-serialize` and `syntax-deserialize
(for-syntax "stxcase-scheme.rkt"))
@ -40,6 +41,7 @@
(all-from "cert.rkt")
(all-from "submodule.rkt")
(all-from "generic-interfaces.rkt")
(all-from "print-value-columns.rkt")
(all-from "kw-syntax-binding.rkt")
(all-from "kw-syntax-serialize.rkt")
(for-syntax syntax-rules syntax-id-rules ... _)

View File

@ -0,0 +1,14 @@
(module print-value-columns "pre-base.rkt"
(#%provide print-value-columns)
(define print-value-columns
(make-parameter +inf.0
(lambda (c)
(if (or (eqv? c +inf.0)
(and (exact-integer? c)
; somewhat arbitrary value, enough for "(list"
(> c 5)))
c
(raise-argument-error 'print-value-columns "(or/c +inf.0 (and/c exact-integer? (>/c 5)))" c)))
'print-value-columns)))