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}
|
||||
|
||||
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
|
||||
compared using @racket[equal?], @racket[eqv?], or @racket[eq?], depending on whether
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
of the hash table).
|
||||
|
||||
@refdetails/gory["ephemerons"]{using ephemerons}
|
||||
|
||||
@examples[
|
||||
(define ht (make-weak-hasheq))
|
||||
(let ([g (gensym)])
|
||||
|
|
|
@ -22,6 +22,7 @@ parenthesized forms in a vector constant represent symbols and lists.
|
|||
@examples[
|
||||
(eval:alts @#,racketvalfont{#("a" "b" "c")} #("a" "b" "c"))
|
||||
(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 #(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
|
||||
written directly as expressions are immutable.
|
||||
|
||||
Vector can be converted to lists and vice versa via
|
||||
@racket[list->vector] and @racket[vector->list]; such conversions are
|
||||
Vectors can be converted to lists and vice versa via
|
||||
@racket[vector->list] and @racket[list->vector]; such conversions are
|
||||
particularly useful in combination with predefined procedures on
|
||||
lists. When allocating extra lists seems too expensive, consider
|
||||
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
|
||||
the side-effect of writing output. In such cases the result value is
|
||||
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.
|
||||
|
||||
The @racket[void] procedure takes any number of arguments and returns
|
||||
|
|
Loading…
Reference in New Issue
Block a user