Various improvements to Guide section 3
* Examples * Scheme -> Racket * Grammar & style
This commit is contained in:
parent
ef08cc41e7
commit
30c381f0b1
|
@ -4,7 +4,7 @@
|
||||||
@title[#:tag "hash-tables"]{Hash Tables}
|
@title[#:tag "hash-tables"]{Hash Tables}
|
||||||
|
|
||||||
A @deftech{hash table} implements a mapping from keys to values, where
|
A @deftech{hash table} implements a mapping from keys to values, where
|
||||||
both keys and values can be arbitrary Scheme values, and access and
|
both keys and values can be arbitrary Racket values, and access and
|
||||||
update to the table are normally constant-time operations. Keys are
|
update to the table are normally constant-time operations. Keys are
|
||||||
compared using @racket[equal?], @racket[eqv?], or @racket[eq?], depending on whether
|
compared using @racket[equal?], @racket[eqv?], or @racket[eq?], depending on whether
|
||||||
the hash table is created with @racket[make-hash],
|
the hash table is created with @racket[make-hash],
|
||||||
|
@ -21,7 +21,7 @@ the hash table is created with @racket[make-hash],
|
||||||
|
|
||||||
The @racket[hash], @racket[hasheqv], and @racket[hasheq] functions
|
The @racket[hash], @racket[hasheqv], and @racket[hasheq] functions
|
||||||
create immutable hash tables from an initial set of keys and values,
|
create immutable hash tables from an initial set of keys and values,
|
||||||
which each value is provided as an argument after its key. Immutable
|
in which each value is provided as an argument after its key. Immutable
|
||||||
hash tables can be extended with @racket[hash-set], which produces a
|
hash tables can be extended with @racket[hash-set], which produces a
|
||||||
new immutable hash table in constant time.
|
new immutable hash table in constant time.
|
||||||
|
|
||||||
|
@ -76,10 +76,12 @@ is retained elsewhere.
|
||||||
Beware that even a weak hash table retains its values strongly, as
|
Beware that even a weak hash table retains its values strongly, as
|
||||||
long as the corresponding key is accessible. This creates a catch-22
|
long as the corresponding key is accessible. This creates a catch-22
|
||||||
dependency when a value refers back to its key, so that the mapping is
|
dependency when a value refers back to its key, so that the mapping is
|
||||||
retained permanently. To break the cycle, map the key to an ephemeron
|
retained permanently. To break the cycle, map the key to an @defterm{ephemeron}
|
||||||
that pairs the value with its key (in addition to the implicit pairing
|
that pairs the value with its key (in addition to the implicit pairing
|
||||||
of the hash table).
|
of the hash table).
|
||||||
|
|
||||||
|
@refdetails/gory["ephemerons"]{using ephemerons}
|
||||||
|
|
||||||
@examples[
|
@examples[
|
||||||
(define ht (make-weak-hasheq))
|
(define ht (make-weak-hasheq))
|
||||||
(let ([g (gensym)])
|
(let ([g (gensym)])
|
||||||
|
|
|
@ -22,6 +22,7 @@ parenthesized forms in a vector constant represent symbols and lists.
|
||||||
@examples[
|
@examples[
|
||||||
(eval:alts @#,racketvalfont{#("a" "b" "c")} #("a" "b" "c"))
|
(eval:alts @#,racketvalfont{#("a" "b" "c")} #("a" "b" "c"))
|
||||||
(eval:alts @#,racketvalfont{#(name (that tune))} #(name (that tune)))
|
(eval:alts @#,racketvalfont{#(name (that tune))} #(name (that tune)))
|
||||||
|
(eval:alts @#,racketvalfont{#4(baldwin bruce)} #4(baldwin bruce))
|
||||||
(vector-ref #("a" "b" "c") 1)
|
(vector-ref #("a" "b" "c") 1)
|
||||||
(vector-ref #(name (that tune)) 1)
|
(vector-ref #(name (that tune)) 1)
|
||||||
]
|
]
|
||||||
|
@ -29,8 +30,8 @@ parenthesized forms in a vector constant represent symbols and lists.
|
||||||
Like strings, a vector is either mutable or immutable, and vectors
|
Like strings, a vector is either mutable or immutable, and vectors
|
||||||
written directly as expressions are immutable.
|
written directly as expressions are immutable.
|
||||||
|
|
||||||
Vector can be converted to lists and vice versa via
|
Vectors can be converted to lists and vice versa via
|
||||||
@racket[list->vector] and @racket[vector->list]; such conversions are
|
@racket[vector->list] and @racket[list->vector]; such conversions are
|
||||||
particularly useful in combination with predefined procedures on
|
particularly useful in combination with predefined procedures on
|
||||||
lists. When allocating extra lists seems too expensive, consider
|
lists. When allocating extra lists seems too expensive, consider
|
||||||
using looping forms like @racket[for/fold], which recognize vectors as
|
using looping forms like @racket[for/fold], which recognize vectors as
|
||||||
|
|
|
@ -7,7 +7,7 @@ Some procedures or expression forms have no need for a result
|
||||||
value. For example, the @racket[display] procedure is called only for
|
value. For example, the @racket[display] procedure is called only for
|
||||||
the side-effect of writing output. In such cases the result value is
|
the side-effect of writing output. In such cases the result value is
|
||||||
normally a special constant that prints as @|void-const|. When the
|
normally a special constant that prints as @|void-const|. When the
|
||||||
result of an expression is simply @|void-const|, the REPL does not
|
result of an expression is simply @|void-const|, the @tech{REPL} does not
|
||||||
print anything.
|
print anything.
|
||||||
|
|
||||||
The @racket[void] procedure takes any number of arguments and returns
|
The @racket[void] procedure takes any number of arguments and returns
|
||||||
|
|
Loading…
Reference in New Issue
Block a user