mzlib/pconvert: `add-make-prefix-to-constructor' parameter
Defaults to #f, which fixes constructor-style printing in `plai' and `racket', and is set to #t for the HtDP languages.
This commit is contained in:
parent
f4c1d9da06
commit
c7464dcbd3
|
@ -12,6 +12,7 @@
|
|||
;; Set print-convert options:
|
||||
(booleans-as-true/false #t)
|
||||
(constructor-style-printing #t)
|
||||
(add-make-prefix-to-constructor #f)
|
||||
(abbreviate-cons-as-list (memq 'abbreviate-cons-as-list options))
|
||||
(current-print-convert-hook
|
||||
(let ([ph (current-print-convert-hook)])
|
||||
|
|
|
@ -202,6 +202,7 @@
|
|||
(is-a? val image-snip%) ;; literal image constant
|
||||
(is-a? val bitmap%))) ;; works in other places, so include it here too
|
||||
(parameterize ([pc:booleans-as-true/false #t]
|
||||
[pc:add-make-prefix-to-constructor #t]
|
||||
[pc:abbreviate-cons-as-list (get-abbreviate-cons-as-list)]
|
||||
[pc:current-print-convert-hook
|
||||
(let ([ph (pc:current-print-convert-hook)])
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
booleans-as-true/false
|
||||
named/undefined-handler
|
||||
use-named/undefined-handler
|
||||
add-make-prefix-to-constructor
|
||||
|
||||
print-convert
|
||||
print-convert-expr
|
||||
|
@ -45,6 +46,7 @@
|
|||
(define booleans-as-true/false (make-parameter #t boolean-filter))
|
||||
(define use-named/undefined-handler (make-parameter (lambda (x) #f)))
|
||||
(define named/undefined-handler (make-parameter (lambda (x) #f)))
|
||||
(define add-make-prefix-to-constructor (make-parameter #f))
|
||||
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; share-hash is the hash-table containing info on what cons cells
|
||||
|
@ -452,11 +454,14 @@
|
|||
(let ([constructor
|
||||
(if (print-convert-named-constructor? expr)
|
||||
(print-convert-constructor-name expr)
|
||||
(let* ([name (object-name expr)]
|
||||
[str-name (if (string? name)
|
||||
name
|
||||
(symbol->string name))])
|
||||
(string->symbol (string-append "make-" str-name))))])
|
||||
(let ([name (object-name expr)])
|
||||
(if (and (symbol? name)
|
||||
(not (add-make-prefix-to-constructor)))
|
||||
name
|
||||
(let ([str-name (if (string? name)
|
||||
name
|
||||
(symbol->string name))])
|
||||
(string->symbol (string-append "make-" str-name))))))])
|
||||
`(,constructor
|
||||
,@(map (lambda (x)
|
||||
(if (eq? uniq x)
|
||||
|
|
|
@ -74,6 +74,14 @@ the parameter is used as the representation for the value.
|
|||
The initial value of the parameter is @racket[(lambda (x) #f)].}
|
||||
|
||||
|
||||
@defboolparam[add-make-prefix-to-constructor add-prefix?]{
|
||||
|
||||
A parameter that controls whether a @racketidfont{make-} prefix is
|
||||
added to a constructor name for a structure instance. The initial
|
||||
value of the parameter is @racket[#f].}
|
||||
|
||||
|
||||
|
||||
@defproc[(build-share [v any/c]) ....]{
|
||||
|
||||
Takes a value and computes sharing information used for representing
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#lang racket/base
|
||||
(require (only-in plai define-type)
|
||||
racket/contract)
|
||||
racket/contract
|
||||
mzlib/pconvert
|
||||
racket/pretty)
|
||||
|
||||
(define-type Foo
|
||||
[bar (v any/c)
|
||||
|
@ -33,4 +35,14 @@
|
|||
(check (to-string write (list (bar "a" (list 'b)))) "(#(struct:bar \"a\" (b)))")
|
||||
(check (to-string display (list (bar "a" (list 'b)))) "(#(struct:bar a (b)))")
|
||||
|
||||
;; Check `print-convert' plus `pretty-write'
|
||||
;; as used by DrRacket's "constructor" printing mode:
|
||||
(constructor-style-printing #t)
|
||||
(check (to-string pretty-write (print-convert '(a b))) "(list 'a 'b)\n")
|
||||
(check (to-string pretty-write (print-convert (bar "a" 'b))) "(bar \"a\" 'b)\n")
|
||||
;; "quasiquote" printing mode:
|
||||
(constructor-style-printing #f)
|
||||
(check (to-string pretty-write (print-convert '(a b))) "`(a b)\n")
|
||||
(check (to-string pretty-write (print-convert (bar "a" 'b))) "(bar \"a\" 'b)\n")
|
||||
|
||||
(printf "~a tests passed.\n" success)
|
||||
|
|
|
@ -4,6 +4,9 @@ Regexps are `equal?' when they have the same source [byte] string
|
|||
Numbers, characters, strings, byte strings, and regexps are interned by
|
||||
read and datum->syntax
|
||||
Added read-intern-literal
|
||||
mzlib/pconvert: added add-make-prefix-to-constructor parameter,
|
||||
which changes the default constructor-style printing in DrRacket
|
||||
to avoid a make- prefix; the HtDP languages set the parameter to #t
|
||||
|
||||
Version 5.2.0.3
|
||||
Added module-predefined?
|
||||
|
|
Loading…
Reference in New Issue
Block a user