diff --git a/collects/htdp/bsl/runtime.rkt b/collects/htdp/bsl/runtime.rkt index d612aad346..0a6ac65f79 100644 --- a/collects/htdp/bsl/runtime.rkt +++ b/collects/htdp/bsl/runtime.rkt @@ -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)]) diff --git a/collects/lang/htdp-langs.rkt b/collects/lang/htdp-langs.rkt index 2f4a0a6906..158d6fb94a 100644 --- a/collects/lang/htdp-langs.rkt +++ b/collects/lang/htdp-langs.rkt @@ -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)]) diff --git a/collects/mzlib/pconvert.rkt b/collects/mzlib/pconvert.rkt index 5aa959d585..88f9deb36a 100644 --- a/collects/mzlib/pconvert.rkt +++ b/collects/mzlib/pconvert.rkt @@ -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) diff --git a/collects/mzlib/scribblings/pconvert.scrbl b/collects/mzlib/scribblings/pconvert.scrbl index a6b32b4a04..e1ac97a856 100644 --- a/collects/mzlib/scribblings/pconvert.scrbl +++ b/collects/mzlib/scribblings/pconvert.scrbl @@ -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 diff --git a/collects/tests/plai/printer.rkt b/collects/tests/plai/printer.rkt index c5cb8cb4cf..363486fdb1 100644 --- a/collects/tests/plai/printer.rkt +++ b/collects/tests/plai/printer.rkt @@ -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) diff --git a/doc/release-notes/racket/HISTORY.txt b/doc/release-notes/racket/HISTORY.txt index 47a35a558b..cddd2c5ec4 100644 --- a/doc/release-notes/racket/HISTORY.txt +++ b/doc/release-notes/racket/HISTORY.txt @@ -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?