move symbol->immutable-string and keyword->immutable->string out of racket/base

Move them to new `racket/symbol` and `racket/keyword` libraries to
avoid conflicts with existing packages.
This commit is contained in:
Matthew Flatt 2020-01-30 15:32:08 -07:00
parent fa6e7101df
commit 37ce9478cd
12 changed files with 136 additions and 81 deletions

View File

@ -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[(keyword<? [a-keyword keyword?] [b-keyword keyword?] ...) boolean?]{
Returns @racket[#t] if the arguments are sorted, where the comparison
for each pair of keywords is the same as using
@racket[keyword->string] with @racket[string->bytes/utf-8] and
@racket[bytes<?].
@mz-examples[(keyword<? '#:apple '#:banana)]
@history/arity[]}
@include-section["keywords.scrbl"]
@; ----------------------------------------------------------------------
@include-section["pairs.scrbl"]

View File

@ -0,0 +1,84 @@
#lang scribble/doc
@(require "mz.rkt"
(for-label racket/keyword))
@title[#: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{#:}.
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[(keyword<? [a-keyword keyword?] [b-keyword keyword?] ...) boolean?]{
Returns @racket[#t] if the arguments are sorted, where the comparison
for each pair of keywords is the same as using
@racket[keyword->string] with @racket[string->bytes/utf-8] and
@racket[bytes<?].
@mz-examples[(keyword<? '#:apple '#:banana)]
@history/arity[]}
@; ----------------------------------------
@section{Additional Keyword Functions}
@note-lib[racket/keyword]
@(define keyword-eval (make-base-eval))
@examples[#:hidden #:eval keyword-eval (require racket/keyword)]
@history[#:added "7.6"]
@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.
@examples[#:eval keyword-eval
(keyword->immutable-string '#:apple)
(immutable? (keyword->immutable-string '#:apple))]
@history[#:added "7.6"]}
@; ----------------------------------------
@close-eval[keyword-eval]

View File

@ -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[bytes<?].
@history/arity[]}
@; ----------------------------------------
@section{Additional Symbol Functions}
@note-lib[racket/symbol]
@(define symbol-eval (make-base-eval))
@examples[#:hidden #:eval symbol-eval (require racket/symbol)]
@history[#:added "7.6"]
@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.
@examples[#:eval symbol-eval
(symbol->immutable-string 'Apple)
(immutable? (symbol->immutable-string 'Apple))]
@history[#:added "7.6"]}
@; ----------------------------------------
@close-eval[symbol-eval]

View File

@ -6,6 +6,8 @@
(require racket/flonum
racket/function
racket/list
racket/symbol
racket/keyword
(prefix-in k: '#%kernel))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -0,0 +1,4 @@
#lang racket/base
(require (only-in '#%kernel keyword->immutable-string))
(provide keyword->immutable-string)

View File

@ -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

View File

@ -0,0 +1,4 @@
#lang racket/base
(require (only-in '#%kernel symbol->immutable-string))
(provide symbol->immutable-string)

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -1,5 +1,6 @@
#lang racket/base
(require racket/fixnum
racket/symbol
"wrap.rkt")
(provide infer-procedure-name)

View File

@ -1,6 +1,7 @@
#lang racket/base
(require racket/unsafe/undefined
racket/fixnum
racket/symbol
"match.rkt"
"wrap.rkt"
"path-for-srcloc.rkt"