diff options
| author | 2021-07-20 22:48:49 -0400 | |
|---|---|---|
| committer | 2021-07-20 22:48:49 -0400 | |
| commit | e7d30dc613ada003f5bbf8caeddafb9b40cb5f1a (patch) | |
| tree | 186fd811d3138eaa25da85775162b9996e4d3a4a | |
| parent | Fix typo. (diff) | |
MN-W review
| -rw-r--r-- | srfi-225.html | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/srfi-225.html b/srfi-225.html index 63dea4e..70fa2e7 100644 --- a/srfi-225.html +++ b/srfi-225.html @@ -51,7 +51,6 @@ similar to an existing hash table.</p> <p>In order for the system to know that an object is a dictionary, a predicate must be defined that recognizes that type of dictionary. Then the predicate must be registered along with procedures that know how to manipulate the dictionary. At least the six basic dictionary procedures (see below) must be registered, but more may be provided at registration time.</p> <p>We call a specific key-value pair an <em>association</em>. This is why an alist, or association list, is called that; it is a list of associations represented as pairs.</p> <p>When a key argument is said to be the same as some key of the dictionary, it means that they are the same in the sense of the dictionary’s equality predicate. It is assumed that no dictionary contains two keys that are the same in this sense.</p> -<p>Dictionaries are said in this SRFI to be <em>similar</em> if they are of the same type and have the same <a href="https://srfi.schemers.org/srfi-128/srfi-128.html">SRFI 128</a> comparator.</p> <h3 id="lists-as-dictionaries">Lists as dictionaries</h3> <p>The exact set of pre-registered dictionaries depends on their availability in a given implementation. However, lists are supported as dictionaries using the specification in this section. If two keys are the same (in the sense of the specified equality predicate), then all but the first are treated as if they did not exist.</p> <p>If the car of a list is a symbol, then the list is assumed to be a property list, alternating symbol keys with values. Mutation operations actually mutate the property list whenever possible. The equality predicate of this type of dictionary is <code>eq?</code>.</p> @@ -60,7 +59,7 @@ similar to an existing hash table.</p> <h3 id="predicates">Predicates</h3> <p><code>(dictionary?</code> <em>obj</em><code>)</code></p> <p>Returns <code>#t</code> if <em>obj</em> answers <code>#t</code> to some registered predicate, and <code>#f</code> otherwise.</p> -<blockquote><pre>(define dict '((1 . 2) (3 . 4) (5 . 6))) +<blockquote><pre>(define dict (list '(1 . 2) '(3 . 4) '(5 . 6))) (dictionary? dict) => #t</pre></blockquote> <p><code>(dict-empty?</code> <em>dictionary</em><code>)</code></p> <p>Returns <code>#t</code> if <em>dictionary</em> contains no associations and <code>#f</code> if it does contain associations.</p> @@ -86,7 +85,7 @@ similar to an existing hash table.</p> <blockquote><pre>; new values are prepended (dict-set! dict 7 8) => ((7 . 8) (1 . 2) (3 . 4) (5 . 6)) (dict-set! dict 3 5) => ((3 . 5) (1 . 2) (3 . 4) (5 . 6)</pre></blockquote> -<p><code>(dict-adjoin!</code> <em>dictionary obj</em><code>)</code></p> +<p><code>(dict-adjoin!</code> <em>dictionary objs</em><code>)</code></p> <p>Returns a dictionary that contains all the associations of <em>dictionary</em> plus those specified by <em>objs</em>, which alternate between keys and values. If a key to be added already exists in <em>dictionary</em>, the old value prevails.</p> <blockquote><pre>; new values are prepended (dict-adjoin! dict 7 8) => ((7 . 8) (1 . 2) (3 . 4) (5 . 6)) @@ -132,7 +131,7 @@ Otherwise, returns two values, a dictionary that contains all the associations o <p>Returns a dictionary that contains all the associations of <em>dictionary</em> except those that satisfy <em>pred</em> when called on the key and value.</p> <blockquote><pre>(dict-remove! (lambda (k) (= k 1)) dict) => ((3 . 4) (5 . 6))</pre></blockquote> <p><code>(dict-search!</code> <em>dictionary key failure success</em><code>)</code></p> -<p>This procedure is a workhorse for dictionary lookup, insert, and delete. The dictionary <em>dictionary</em> is searched for an association whose key is the same as <em>key</em> in the sense of <em>dictionary</em>’s comparator. If one is not found, then the <em>failure</em> procedure is tail-called with two continuation arguments, <em>insert</em> and <em>ignore</em>, and is expected to tail-call one of them.</p> +<p>This procedure is a workhorse for dictionary lookup, insert, and delete. The dictionary <em>dictionary</em> is searched for an association whose key is the same as <em>key</em> in the sense of <em>dictionary</em>. If one is not found, then the <em>failure</em> procedure is tail-called with two continuation arguments, <em>insert</em> and <em>ignore</em>, and is expected to tail-call one of them.</p> <p>However, if such an association is found, then the <em>success</em> procedure is tail-called with the matching key of <em>dictionary</em>, the associated value, and two continuation arguments, <em>update</em> and <em>remove</em>, and is expected to tail-call one of them.</p> <p>It is an error if the continuation arguments are invoked other than in tail position in the <em>failure</em> and <em>success</em> procedures. It is also an error if the <em>failure</em> and <em>success</em> procedures return to their implicit continuation without invoking one of their arguments.</p> <p>The behaviors of the continuations are as follows (where <em>obj</em> is any Scheme object):</p> @@ -197,7 +196,8 @@ one for each of the four continuations: <blockquote><pre>(dict-size dict) => 0</pre></blockquote> <p><code>(dict-for-each</code> <em>proc dictionary</em><code>)</code></p> <p>Invokes <em>proc</em> on each key of <em>dictionary</em> and its corresponding value in that order. This procedure is used for doing operations on the whole dictionary. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. Returns an unspecified value.</p> -<blockquote><pre>(dict-for-each write dict) => unspecified +<blockquote><pre>(define (write-key key value) (write key)) +(dict-for-each write-key dict) => unspecified ; writes "135" to current output</pre></blockquote> <p><code>(dict-count</code> <em>pred dictionary</em><code>)</code></p> <p>Passes each association of dictionary as two arguments to <em>pred</em> and returns the number of times that <em>pred</em> returned true as an an exact integer.</p> @@ -216,7 +216,7 @@ one for each of the four continuations: <p>Returns a list of the keys of <em>dictionary</em>. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. The order may change when new elements are added to <em>dictionary</em>.</p> <blockquote><pre>(dict-keys dict) => (1 3 5)</pre></blockquote> <p><code>(dict-values</code> <em>dictionary</em><code>)</code></p> -<p>Returns a list of the values of <em>dictionary</em>. The results returned by <code>dict-keys</code> and <code>dict-values</code> are ordered consistently.</p> +<p>Returns a list of the values of <em>dictionary</em>. The results returned by <code>dict-keys</code> and <code>dict-values</code> are not necessarily ordered consistently.</p> <blockquote><pre>(dict-values dict) => (2 4 6)</pre></blockquote> <p><code>(dict-entries</code> <em>dictionary</em><code>)</code></p> <p>Returns two values, the results of calling <code>dict-keys</code> and the result of calling <code>dict-values</code> on <em>dictionary</em>.</p> |
