diff options
| author | 2021-12-15 12:30:53 -0500 | |
|---|---|---|
| committer | 2021-12-15 12:30:53 -0500 | |
| commit | b5f18cabe6f7db4f1e4366c09232217e278b15f0 (patch) | |
| tree | 9ffbb9ce4d701ae36d281ddb2860e2bf71f1f861 | |
| parent | dto and find-update (diff) | |
removed subset and interval procs
| -rw-r--r-- | srfi-225.html | 61 |
1 files changed, 17 insertions, 44 deletions
diff --git a/srfi-225.html b/srfi-225.html index 5a6799c..33ea487 100644 --- a/srfi-225.html +++ b/srfi-225.html @@ -47,7 +47,7 @@ None at present. <p>We call a specific key-value combination 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>A <em>dictionary</em> or <em>dict</em> is a collection of associations which may be inherently ordered by their keys or not. In principle an <em>equality predicate</em> is enough, given a key, to determine whether an association with that key exists in the dictionary. However, for efficiency most dictionaries require an <em>ordering predicate</em> or a <em>hash function</em> as well. <p>When a key argument is said to be the <em>same</em> as some key of the dictionary, it means that they are the same in the sense of the dictionary’s implicit or explicit equality predicate. -Two dictionaries are <em>similar</em> if they are of the same type and have the same equality predicate and the same ordering predicate and/or hash function.</p> +Two dictionaries are <em>similar</em> if they have the same DTO and have the same equality predicate and the same ordering predicate and/or hash function.</p> <p>When an association is deleted from a dictionary other than by <code>dict-remove</code>, or is updated, any other associations with the same key remain in the dictionary. Whether such duplicate keys are possible depends on the dictionary type. Alists do allow them:</p> <blockquote><pre>(dict-delete '((1 . 2) (1 . 3) (2 . 4)) 1) => ((1 . 3) (2 . 4))</code>. </pre></blockquote> @@ -99,6 +99,7 @@ Consequently, previous examples don't affect later ones. (dict-ref/default aed dict 1 #f) => #f</pre></blockquote> <h3 id="update-procedures">Update procedures</h3> <p>All update procedures exist in pairs, with and without a final <code>!</code>. The descriptions apply to the procedures without <code>!</code>; the procedures with <code>!</code> mutate their dictionary argument and do not return a dictionary value. Only one set of procedures is supported by any dictionary type: for example, SRFI 125 hash tables are impure and support only mutation, whereas SRFI 146 mappings are pure and support only functional update. The <code>dict-pure?</code> procedure can be used to determine which set is usable.</p> +<p>Updates are not permitted while any generic procedure is running that takes a procedure argument.</p> <p><code>(dict-set</code> <em>dto dict obj</em> …<code>)</code><br> <code>(dict-set!</code> <em>dto dict obj</em> …<code>)</code></p> <p>Returns a dictionary that contains all the associations of <em>dict</em> plus those specified by <em>objs</em>, which find-updatenate between keys and values. If a key to be added already exists in <em>dict</em>, the new value prevails.</p> @@ -174,7 +175,7 @@ Otherwise, returns two values, a dictionary that contains all the associations o 2</pre></blockquote> <p><code>(dict-map</code> <em>dto proc dict</em><code>)</code><br> <code>(dict-map!</code> <em>dto proc dict</em><code>)</code></p> -<p>Returns a dictionary similar to <em>dict</em> that maps each key of <em>dict</em> to the <em>proc</em> on the key and corresponding value of <em>dict</em>.</p> +<p>Returns a dictionary similar to <em>dict</em> that maps each of <em>dict</em> to the result of applying <em>proc</em> to the key and corresponding value of <em>dict</em>.</p> <blockquote><pre>(dict-map (lambda (k v) (cons v k)) aed dict) => ((2 . 1) (4 . 3) (6 . 5))</pre></blockquote> <p><code>(dict-filter</code> <em>dto pred dict</em><code>)</code><br> @@ -266,7 +267,7 @@ one for each of the four procedures: <p>Returns a list of the values of <em>dict</em>. The results returned by <code>dict-keys</code> and <code>dict-values</code> are not necessarily ordered consistently.</p> <blockquote><pre>(dict-values aed dict) => (2 4 6)</pre></blockquote> <p><code>(dict-entries</code> <em>dto dict</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>dict</em>.</p> +<p>Returns two list values, the result of calling <code>dict-keys</code> and the result of mapping <code>proc</code> over the first list.</p> <blockquote><pre>(dict-entries aed dict) => ; 2 values (1 3 5) (2 4 6)</pre></blockquote> @@ -283,7 +284,6 @@ one for each of the four procedures: </pre></blockquote> <p><code>(dict->alist</code> <em>dto dict</em><code>)</code></p> <p>Returns an alist whose keys and values are the keys and values of <em>dict</em>.</p> -<p>Add <code>dict-map</code>, <code>dict-filter</code>, <code>dict-remove</code>, and <code>dict-find-update</code>. </p> @@ -296,29 +296,22 @@ and <code>dict-find-update</code>. <blockquote><pre>(define (write-key key value) (write key)) (dict-for-each write-key aed dict) => unspecified ; writes "135" to current output</pre></blockquote> -<p><code>(dict-for-each<</code> <em>dto proc dict key</em><code>)</code><br> -<code>(dict-for-each<=</code> <em>dto proc dict key</em><code>)</code><br> -<code>(dict-for-each></code> <em>dto proc dict key</em><code>)</code><br> -<code>(dict-for-each>=</code> <em>dto proc dict key</em><code>)</code></p> -<p>Invokes <em>proc</em> on each key of <em>dict</em> that is less than / less than or equal to / greater than / greater than or equal to <em>key</em> and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. Returns an unspecified value.</p> -<p><code>(dict-for-each-in-open-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-closed-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-open-closed-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-closed-open-interval</code> <em>dto proc dict key1 key2</em><code>)</code></p> -<p>Invokes <em>proc</em> on each key of <em>dict</em> that is that is within the specified interval between <em>key1</em> and <em>key2</em>, and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. Returns an unspecified value.</p> <h3 id="generator-procedures">Generator procedures</h3> -<p><code>(make-dict-generator</code> <em>dto dict</em><code>)</code></p> -<p>Returns a <a href="https://srfi.schemers.org/srfi-158/srfi-158.html">generator</a> that when invoked returns the associations of <em>dict</em> as pairs. When no associations are left, returns an end-of-file object. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. It is an error to mutate <em>dict</em> until the generator is exhausted.</p> -<p><code>(dict-set-accumulator</code> <em>dto dict</em><code>)</code></p> -<p>Returns a SRFI 158 accumulator procedure that when invoked on a pair adds the <code>car</code> and <code>cdr</code> of the pair as a key and value, returning the new value of the dictionary. If invoked on an end-of-file object, no action is taken and <em>dict</em> is returned. If a key to be added already exists in dictionary, the new value prevails.</p> -<p><code>(dict-adjoin-accumulator</code> <em>dto dict</em><code>)</code></p> -<p>The same as <code>dict-set-accumulator</code>, except that if a key to be added already exists in dictionary, the old value prevails.</p> +<p><code>(dict->generator</code> <em>dto dict</em><code>)</code></p> +<p>Returns a <a href="https://srfi.schemers.org/srfi-158/srfi-158.html">SRFI 158 generator</a> that when invoked returns the associations of <em>dict</em> as pairs. When no associations are left, returns an end-of-file object. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. It is an error to mutate <em>dict</em> until the generator is exhausted.</p> +<p><code>(dict-set-accumulator</code> <em>dto dict</em><code>)</code><br> +<code>(dict-set!-accumulator</code> <em>dto dict accum</em><code>)</code></p> +<p>Returns a SRFI 158 accumulator procedure that when invoked on a pair adds the <code>car</code> and <code>cdr</code> of the pair as a key and value of <em>dict</em> as if by <em>dict-set</em>, eventually returning the new value of <em>dict</em>. If invoked on an end-of-file object, no action is taken and <em>dict</em> is returned.</p> +<p>The <code>!</code> variant uses <code>dict-set!</code> instead. +<p><code>(dict-adjoin-accumulator</code> <em>dto dict</em><code>)</code><br> +<code>(dict-adjoin!-accumulator!</code> <em>dto dict</em><code>)</code></p> +<p>The same as <code>dict-set!-accumulator</code>, except using <code>dict-adjoin(!)</code>. </p> <h3 id="dictionary-type-object-procedures">Dictionary type object procedures</h3> <p><code>(dto?</code> <em>obj</em><code>)</code></p> <p>Returns <code>#t</code> if <em>obj</em> is a DTO, and <code>#f</code> otherwise.</p> <p><code>(make-dto</code> <em>arg</em> …<code>)</code><br> <code>(dto (</code><em>proc-id procname</em><code>)</code> …<code>)</code> [syntax]</p> -<p>Returns a new DTO providing procedures that allow manipulation of dictionaries of that type. The <em>args</em> are find-updatenately <em>proc-ids</em> and corresponding <em>procs</em>.</p> +<p>Returns a new DTO providing procedures that allow manipulation of dictionaries of a new type. The <em>args</em> are alternately <em>proc-ids</em> and corresponding <em>procs</em>.</p> <p>A <em>proc-id</em> argument is the value of a variable whose name is the same as a procedure (except those in this section and the Exceptions section) suffixed with <code>-id</code>, and a <em>proc</em> argument is the specific procedure implementing it for this type. Note that there is only one proc-id variable for each pair of pure and impure procedures: the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <code>dict-map-id</code>.</p> @@ -332,7 +325,7 @@ the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <li><code>dict-remove-id</code></li> <li><code>dict-size-id</code></li> </ul> -<p>Note that it is not an error to omit any of these, but some dictionary procedures may be unavailable.</p> +<p>Note that if any of these are not provided, an implementation-defined set of generic procedures will generate errors if invoked.</p> <p>There are additional proc-id variables that may be provided with corresponding procedures in order to increase efficiency. For example, it is not necessary to provide a <code>dict-ref</code> procedure, because the default version is built on top of <code>dict-find-update</code> or <code>dict-find-update!</code>. But if the underlying dictionary provides its own <code>-ref</code> procedure, it may be more efficient to specify it to <code>make-dto</code> using <code>dict-ref-id</code>. Here is the list of additional proc-id variables:</p> <ul> <li><code>dict->alist-id</code></li> @@ -348,15 +341,7 @@ the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <li><code>dict-every-id</code></li> <li><code>dict-filter-id</code></li> <li><code>dict-fold-id</code></li> -<li><code>dict-for-each<-id</code></li> -<li><code>dict-for-each<=-id</code></li> <li><code>dict-for-each-id</code></li> -<li><code>dict-for-each-in-closed-interval-id</code></li> -<li><code>dict-for-each-in-closed-open-interval-id</code></li> -<li><code>dict-for-each-in-open-closed-interval-id</code></li> -<li><code>dict-for-each-in-open-interval-id</code></li> -<li><code>dict-for-each>-id</code></li> -<li><code>dict-for-each>=-id</code></li> <li><code>dict-intern-id</code></li> <li><code>dict-keys-id</code></li> <li><code>dict-map->list-id</code></li> @@ -372,7 +357,7 @@ the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <li><code>dict-update/default-id</code></li> <li><code>dict-values-id</code></li> <li><code>dict=?-id</code></li> -<li><code>make-dict-generator-id</code></li> +<li><code>dict->generator-id</code></li> </ul> <p>The <code>dto</code> macro behaves like a wrapper around <code>make-dto</code> with parentheses around each <em>procid-procname</em> pair. The macro may also verify that the <em>proc-ids</em> are valid, that there are no duplicates, etc.</p> <p><code>(make-alist-dto</code> <em>equal</em><code>)</code></p> @@ -507,19 +492,7 @@ new dictionary types that may not have complete dictionary APIs:</p> <dt>dict-for-each>=</dt> <dd>dict-for-each</dd> - <dt>dict-for-each-in-open-interval</dt> - <dd>dict-for-each</dd> - - <dt>dict-for-each-in-closed-interval</dt> - <dd>dict-for-each</dd> - - <dt>dict-for-each-in-open-closed-interval</dt> - <dd>dict-for-each</dd> - - <dt>dict-for-each-in-closed-open-interval</dt> - <dd>dict-for-each</dd> - - <dt>make-dict-generator</dt> + <dt>dict->generator</dt> <dd>dict-entries</dd> <dt>dict-set-accumulator</dt> |
