diff --git a/pkgs/racket-doc/scribblings/reference/data.scrbl b/pkgs/racket-doc/scribblings/reference/data.scrbl index f0375a6b81..5d9f8fab95 100644 --- a/pkgs/racket-doc/scribblings/reference/data.scrbl +++ b/pkgs/racket-doc/scribblings/reference/data.scrbl @@ -35,70 +35,7 @@ manipulating instances of the datatype. @include-section["regexps.scrbl"] @; ------------------------------------------------------------ -@section[#:tag "keywords"]{Keywords} - -@guideintro["keywords"]{keywords} - -A @deftech{keyword} is like an @tech{interned} symbol, but its printed -form starts with @litchar{#:}, and a keyword cannot be used as an -identifier. Furthermore, a keyword by itself is not a valid -expression, though a keyword can be @racket[quote]d to form an -expression that produces the symbol. - -Two keywords are @racket[eq?] if and only if they print the same -(i.e., keywords are always @tech{interned}). - -Like symbols, keywords are only weakly held by the internal keyword -table; see @secref["symbols"] for more information. - -@see-read-print["keyword"]{keywords} - -@defproc[(keyword? [v any/c]) boolean?]{ - -Returns @racket[#t] if @racket[v] is a keyword, @racket[#f] otherwise. - -@mz-examples[(keyword? '#:apple) - (keyword? 'define) - (keyword? '#:define)]} - - -@defproc[(keyword->string [keyword keyword?]) string?]{ - -Returns a string for the @racket[display]ed form of @racket[keyword], -not including the leading @litchar{#:}. - -@mz-examples[(keyword->string '#:apple)]} - - -@defproc[(keyword->immutable-string [sym keyword?]) (and/c string? immutable?)]{ - -Like @racket[keyword->string], but the result is an immutable string, -not necessarily freshly allocated. - -@mz-examples[(keyword->immutable-string '#:apple) - (immutable? (keyword->immutable-string '#:apple))] - -@history[#:added "7.5.0.14"]} - - -@defproc[(string->keyword [str string?]) keyword?]{ - -Returns a keyword whose @racket[display]ed form is the same as that of -@racket[str], but with a leading @litchar{#:}. - -@mz-examples[(string->keyword "apple")]} - - -@defproc[(keywordstring] with @racket[string->bytes/utf-8] and -@racket[bytesstring [keyword keyword?]) string?]{ + +Returns a string for the @racket[display]ed form of @racket[keyword], +not including the leading @litchar{#:}. + +See also @racket[keyword->immutable-string] from +@racketmodname[racket/keyword]. + +@mz-examples[(keyword->string '#:apple)]} + + +@defproc[(string->keyword [str string?]) keyword?]{ + +Returns a keyword whose @racket[display]ed form is the same as that of +@racket[str], but with a leading @litchar{#:}. + +@mz-examples[(string->keyword "apple")]} + + +@defproc[(keywordstring] with @racket[string->bytes/utf-8] and +@racket[bytesimmutable-string [sym keyword?]) (and/c string? immutable?)]{ + +Like @racket[keyword->string], but the result is an immutable string, +not necessarily freshly allocated. + +@examples[#:eval keyword-eval + (keyword->immutable-string '#:apple) + (immutable? (keyword->immutable-string '#:apple))] + +@history[#:added "7.6"]} + +@; ---------------------------------------- +@close-eval[keyword-eval] diff --git a/pkgs/racket-doc/scribblings/reference/symbols.scrbl b/pkgs/racket-doc/scribblings/reference/symbols.scrbl index 4200e0620c..f26411165e 100644 --- a/pkgs/racket-doc/scribblings/reference/symbols.scrbl +++ b/pkgs/racket-doc/scribblings/reference/symbols.scrbl @@ -1,5 +1,6 @@ #lang scribble/doc -@(require "mz.rkt") +@(require "mz.rkt" + (for-label racket/symbol)) @title[#:tag "symbols"]{Symbols} @@ -62,20 +63,12 @@ used as an ephemeron key (see @secref["ephemerons"]). allocated mutable string whose characters are the same as in @racket[sym]. +See also @racket[symbol->immutable-string] from +@racketmodname[racket/symbol]. + @mz-examples[(symbol->string 'Apple)]} -@defproc[(symbol->immutable-string [sym symbol?]) (and/c string? immutable?)]{ - -Like @racket[symbol->string], but the result is an immutable string, -not necessarily freshly allocated. - -@mz-examples[(symbol->immutable-string 'Apple) - (immutable? (symbol->immutable-string 'Apple))] - -@history[#:added "7.5.0.14"]} - - @defproc[(string->symbol [str string?]) symbol?]{Returns an @tech{interned} symbol whose characters are the same as in @racket[str]. @@ -121,3 +114,26 @@ for each pair of symbols is the same as using @racket[bytesimmutable-string [sym symbol?]) (and/c string? immutable?)]{ + +Like @racket[symbol->string], but the result is an immutable string, +not necessarily freshly allocated. + +@examples[#:eval symbol-eval + (symbol->immutable-string 'Apple) + (immutable? (symbol->immutable-string 'Apple))] + +@history[#:added "7.6"]} + +@; ---------------------------------------- +@close-eval[symbol-eval] diff --git a/pkgs/racket-test-core/tests/racket/basic.rktl b/pkgs/racket-test-core/tests/racket/basic.rktl index fb32d379f6..f60ef71943 100644 --- a/pkgs/racket-test-core/tests/racket/basic.rktl +++ b/pkgs/racket-test-core/tests/racket/basic.rktl @@ -6,6 +6,8 @@ (require racket/flonum racket/function racket/list + racket/symbol + racket/keyword (prefix-in k: '#%kernel)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/racket/collects/racket/keyword.rkt b/racket/collects/racket/keyword.rkt new file mode 100644 index 0000000000..0cd3038fe1 --- /dev/null +++ b/racket/collects/racket/keyword.rkt @@ -0,0 +1,4 @@ +#lang racket/base +(require (only-in '#%kernel keyword->immutable-string)) + +(provide keyword->immutable-string) diff --git a/racket/collects/racket/private/pre-base.rkt b/racket/collects/racket/private/pre-base.rkt index 3d297182cf..94c02dd786 100644 --- a/racket/collects/racket/private/pre-base.rkt +++ b/racket/collects/racket/private/pre-base.rkt @@ -222,7 +222,9 @@ prop:incomplete-arity prop:method-arity-error list-pair? interned-char? true-object? random - collection-path collection-file-path) + collection-path collection-file-path + symbol->immutable-string + keyword->immutable-string) (all-from "reqprov.rkt") (all-from-except "for.rkt" define-in-vector-like diff --git a/racket/collects/racket/symbol.rkt b/racket/collects/racket/symbol.rkt new file mode 100644 index 0000000000..355388960a --- /dev/null +++ b/racket/collects/racket/symbol.rkt @@ -0,0 +1,4 @@ +#lang racket/base +(require (only-in '#%kernel symbol->immutable-string)) + +(provide symbol->immutable-string) diff --git a/racket/src/expander/expand/env.rkt b/racket/src/expander/expand/env.rkt index 4f7e882648..d59d633152 100644 --- a/racket/src/expander/expand/env.rkt +++ b/racket/src/expander/expand/env.rkt @@ -1,5 +1,6 @@ #lang racket/base -(require "../common/memo.rkt" +(require racket/symbol + "../common/memo.rkt" "../syntax/syntax.rkt" "../syntax/error.rkt" "../syntax/scope.rkt" diff --git a/racket/src/io/print/main.rkt b/racket/src/io/print/main.rkt index 2c8106822d..a1747b7c30 100644 --- a/racket/src/io/print/main.rkt +++ b/racket/src/io/print/main.rkt @@ -1,6 +1,8 @@ #lang racket/base (require racket/flonum racket/fixnum + racket/symbol + racket/keyword "../common/check.rkt" "../port/output-port.rkt" "../port/input-port.rkt" @@ -232,9 +234,9 @@ [(keyword? v) (let ([max-length (write-string/max "#:" o max-length)]) (cond - [(eq? mode DISPLAY-MODE) (write-string/max (keyword->string v) o max-length)] + [(eq? mode DISPLAY-MODE) (write-string/max (keyword->immutable-string v) o max-length)] [else - (print-symbol (string->symbol (keyword->string v)) o max-length config + (print-symbol (string->symbol (keyword->immutable-string v)) o max-length config #:for-keyword? #t)]))] [(char? v) (cond diff --git a/racket/src/io/print/symbol.rkt b/racket/src/io/print/symbol.rkt index 5e0243cff7..9c26039f62 100644 --- a/racket/src/io/print/symbol.rkt +++ b/racket/src/io/print/symbol.rkt @@ -1,5 +1,6 @@ #lang racket/base -(require "../port/string-output.rkt" +(require racket/symbol + "../port/string-output.rkt" "../string/number.rkt" "write-with-max.rkt" "parameter.rkt" diff --git a/racket/src/schemify/infer-name.rkt b/racket/src/schemify/infer-name.rkt index 9519ee4045..0cf4898676 100644 --- a/racket/src/schemify/infer-name.rkt +++ b/racket/src/schemify/infer-name.rkt @@ -1,5 +1,6 @@ #lang racket/base (require racket/fixnum + racket/symbol "wrap.rkt") (provide infer-procedure-name) diff --git a/racket/src/schemify/interpret.rkt b/racket/src/schemify/interpret.rkt index e9e07cadff..3a6054d0bf 100644 --- a/racket/src/schemify/interpret.rkt +++ b/racket/src/schemify/interpret.rkt @@ -1,6 +1,7 @@ #lang racket/base (require racket/unsafe/undefined racket/fixnum + racket/symbol "match.rkt" "wrap.rkt" "path-for-srcloc.rkt"