diff options
Diffstat (limited to '')
-rw-r--r-- | srfi-225.html | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/srfi-225.html b/srfi-225.html index d781760..fef8e5a 100644 --- a/srfi-225.html +++ b/srfi-225.html @@ -51,24 +51,24 @@ similar to an existing hash table.</p> <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))) -(dictionary? dict) => #t</code></blockquote> +(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> <blockquote><pre>(dict-empty? '()) => #t -(dict-empty? dict) => #f</code></blockquote> +(dict-empty? dict) => #f</pre></blockquote> <p><code>(dict-contains?</code> <em>dictionary key</em><code>)</code></p> <blockquote><pre>(dict-contains? dict 1) => #t -(dict-contains? dict 2) => #f</code></blockquote> +(dict-contains? dict 2) => #f</pre></blockquote> <p>Returns <code>#t</code> if one of the keys of <em>dictionary</em> is the same as <em>key</em>, and <code>#f</code> otherwise.</p> <h3 id="lookup">Lookup</h3> <p><code>(dict-ref</code> <em>dictionary key</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> <p>If <em>key</em> is the same as some key of <em>dictionary</em>, then invokes <em>success</em> on the corresponding value and returns its result. If <em>key</em> is not a key of <em>dictionary</em>, then invokes the thunk <em>failure</em> and returns its result. The default value of <em>failure</em> signals an error; the default value of <em>success</em> is the identity procedure.</p> <blockquote><pre>(dict-ref dict 1 (lambda () '()) list) => (1) ; Success wraps value in a list -(dict-ref dict 2 (lambda () '()) list) => () ; Failure returns empty list</code></blockquote> +(dict-ref dict 2 (lambda () '()) list) => () ; Failure returns empty list</pre></blockquote> <p><code>(dict-ref/default</code> <em>dictionary key default</em><code>)</code></p> <p>If <em>key</em> is the same as some key of <em>dictionary</em> then returns the corresponding value. If not, then returns <em>default</em>.</p> <blockquote><pre>(dict-ref/default dict 1 #f) => 1 -(dict-ref/default dict 1 #f) => #f</code></blockquote> +(dict-ref/default dict 1 #f) => #f</pre></blockquote> <h3 id="mutation">Mutation</h3> <p>All these procedures are linear-update: they may return either a new dictionary object (which may or may not share storage with the <em>dictionary</em> argument), or the same dictionary object, mutated. In either case, it is an error to access the dictionary later through any other reference to it, as that reference may have been invalidated.</p> <p><code>(dict-set!</code> <em>dictionary obj</em> …<code>)</code></p> @@ -80,19 +80,19 @@ similar to an existing hash table.</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)) -(dict-adjoin! dict 3 5) => ((1 . 2) (3 . 4) (5 . 6)</code></blockquote> +(dict-adjoin! dict 3 5) => ((1 . 2) (3 . 4) (5 . 6)</pre></blockquote> <p><code>(dict-delete!</code> <em>dictionary key</em> …<code>)</code></p> <p>Returns a dictionary that contains all the associations of <em>dictionary</em> except those whose keys are the same as one of the <em>keys</em>.</p> <blockquote><pre>; new values are prepended (dict-delete! dict 1 3) => ((5. 6)) ; may share -(dict-delete! dict 5) => ((1 . 2) (3 . 4)</code></blockquote> +(dict-delete! dict 5) => ((1 . 2) (3 . 4)</pre></blockquote> <p><code>(dict-delete-all!</code> <em>dictionary keylist</em><code>)</code></p> <p>Returns a dictionary with all the associations of <em>dictionary</em> except those whose keys are the same as some member of <em>keylist</em>.</p> -<blockquote><pre>(dict-delete-all! dict '(1 3)) => ((5 . 6))</code></blockquote> +<blockquote><pre>(dict-delete-all! dict '(1 3)) => ((5 . 6))</pre></blockquote> <p><code>(dict-replace!</code> <em>dictionary key value</em><code>)</code></p> <p>Returns a dictionary that contains all the associations of <em>dictionary</em> except as follows: If <em>key</em> is the same as a key of <em>dictionary</em>, then the association for that key is omitted and replaced by the association defined by the pair <em>key</em> and <em>value</em>. If there is no such key in <em>dictionary</em>, then dictionary is returned unchanged.</p> -<blockquote><pre>(dict-replace! dict 1 3) => ((1 . 3) (1 . 2) (3 . 4) (5 . 6)) </code></blockquote> -<p><code>(dict-intern!</code> <em>dictionary key failure</em>)</code></p> +<blockquote><pre>(dict-replace! dict 1 3) => ((1 . 3) (1 . 2) (3 . 4) (5 . 6)) </pre></blockquote> +<p><code>(dict-intern!</code> <em>dictionary key failure</em>)</p> <p>If there is a key in <em>dictionary</em> that is the same as <em>key</em>, returns two values, <em>dictionary</em> and the value associated with <em>key</em>. Otherwise, returns two values, a dictionary that contains all the associations of <em>dictionary</em> and in addition a new association that maps <em>key</em> to the result of invoking <em>failure</em>, and the result of invoking <em>failure</em>.</p> <blockquote><pre>(dict-intern! dict 1 (lambda () #f)) => ; 2 values @@ -100,7 +100,7 @@ Otherwise, returns two values, a dictionary that contains all the associations o 3 (dict-intern! dict 2 (lambda () #f)) => ; 2 values ((2 . #f) (1 . 2) (3 . 4) (5 . 6)) - #f</code></blockquote> + #f</pre></blockquote> <p><code>(dict-update!</code> <em>dictionary key updater</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> <p>Retrieves the value of <em>key</em> as if by <code>dict-ref</code>, invokes <em>updater</em> on it, and sets the value of <em>key</em> to be the result of calling <em>updater</em> as if by <code>dict-set</code>, but may do so more efficiently. Returns the updated dictionary. The default value of <em>failure</em> signals an error; the default value of <em>success</em> is the identity procedure.</p> <p><code>(dict-update/default!</code> <em>dictionary key updater default</em><code>)</code></p> @@ -111,16 +111,16 @@ Otherwise, returns two values, a dictionary that contains all the associations o <blockquote><pre>(dict-pop! dict) => # 3 values ((3 . 4) (5 . 6)) 1 - 2</code></blockquote> + 2</pre></blockquote> <p><code>(dict-map!</code> <em>proc dictionary</em><code>)</code></p> <p>Returns a dictionary similar to <em>dictionary</em> that maps each key of <em>dictionary</em> to the value that results from invoking <em>proc</em> on the corresponding key and value of <em>dictionary</em>.</p> -<blockquote><pre>(dict-map! (lambda (k v) (cons v k)) dict) => ((2 . 1) (4 . 3) (6 . 5))</code></blockquote> +<blockquote><pre>(dict-map! (lambda (k v) (cons v k)) dict) => ((2 . 1) (4 . 3) (6 . 5))</pre></blockquote> <p><code>(dict-filter!</code> <em>pred dictionary</em><code>)</code></p> <p>Returns a dictionary similar to <em>dictionary</em> that contains just the associations of <em>dictionary</em> that satisfy <em>pred</em> when it is invoked on the key and value of the association.</p> -<blockquote><pre>(dict-filter! (lambda (k v) (= k 1)) dict) => ((1 . 2))</code></blockquote> +<blockquote><pre>(dict-filter! (lambda (k v) (= k 1)) dict) => ((1 . 2))</pre></blockquote> <p><code>(dict-remove!</code> <em>pred dictionary</em><code>)</code></p> <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))</code></blockquote> +<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>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> @@ -184,45 +184,45 @@ one for each of the four continuations: <h3 id="the-whole-dictionary">The whole dictionary</h3> <p><code>(dict-size</code> <em>dictionary</em><code>)</code></p> <p>Returns an exact integer representing the number of associations in <em>dictionary</em>.</p> -<blockquote><pre>(dict-size dict) => 0</code></blockquote> +<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 - ; writes "135" to current output</code></blockquote> + ; 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> -<blockquote><pre>(dict-count dict (lambda (k v) (even? k))) => 0</code></blockquote> +<blockquote><pre>(dict-count dict (lambda (k v) (even? k))) => 0</pre></blockquote> <p><code>(dict-any</code> <em>pred dictionary</em><code>)</code></p> <p>Passes each association of <em>dictionary</em> as two arguments to <em>pred</em> and returns the value of the first call to <em>pred</em> that returns true, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. If all calls return false, <code>dict-any</code> returns false.</p> <blockquote><pre>(define (both-even? k v) (and (even? k) (even? v))) (dict-any both-even? '((2 . 4) (3 . 5))) => #t -(dict-any both-even? '((1 . 2) (3 . 4))) => #f</code></blockquote> +(dict-any both-even? '((1 . 2) (3 . 4))) => #f</pre></blockquote> <p><code>(dict-every</code> <em>pred dictionary</em><code>)</code></p> <p>Passes each association of <em>dictionary</em> as two arguments to <em>pred</em> and returns <code>#f</code> after the first call to <em>pred</em> that returns false, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. If all calls return true, <code>dict-any</code> returns the value of the last call, or <code>#t</code> if no calls are made.</p> <blockquote><pre>(define (some-even? k v) (or (even? k) (even? v))) (dict-every some-even? '((2 . 3) (3 . 4))) => #t -(dict-every some-even? '((1 . 3) (3 . 4))) => #f</code></blockquote> +(dict-every some-even? '((1 . 3) (3 . 4))) => #f</pre></blockquote> <p><code>(dict-keys</code> <em>dictionary</em><code>)</code></p> <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)</code></blockquote> +<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> -<blockquote><pre>(dict-values dict) => (2 4 6)</code></blockquote> +<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> <blockquote><pre>(dict-entries dict) => ; 2 values (1 3 5) - (2 4 6)</code></blockquote> + (2 4 6)</pre></blockquote> <p><code>(dict-fold</code> <em>proc knil dictionary</em><code>)</code></p> <p>Invokes <em>proc</em> on each association of <em>dictionary</em> with three arguments: the key of the association, the value of the association, and an accumulated result of the previous invocation. For the first invocation, <em>knil</em> is used as the third argument. Returns the result of the last invocation, or <em>knil</em> if there was no invocation.</p> -<blockquote><pre>(dict-fold + 0 '((1 . 2) (3 . 4))) => 10</code></blockquote> +<blockquote><pre>(dict-fold + 0 '((1 . 2) (3 . 4))) => 10</pre></blockquote> <p><code>(dict-map->list</code> <em>proc dictionary</em><code>)</code></p> <p>Returns a list of values that result from invoking <em>proc</em> on the keys and corresponding values of <em>dictionary</em>.</p> -<blockquote><pre>(dict-map->list - dict) => (-1 -1 -1)</code></blockquote> +<blockquote><pre>(dict-map->list - dict) => (-1 -1 -1)</pre></blockquote> <p><code>(dict->alist</code> <em>dictionary</em><code>)</code></p> <p>Returns an alist whose keys and values are the keys and values of <em>dictionary</em>.</p> <blockquote><pre>; plist to alist -(dict->alist '(1 2 3 4 5 6)) => ((1 . 2) (3 . 4) (5 . 6))</code></blockquote> +(dict->alist '(1 2 3 4 5 6)) => ((1 . 2) (3 . 4) (5 . 6))</pre></blockquote> <h3 id="registering-dictionary-types">Registering dictionary types</h3> <p>The following procedure registers new dictionary types. It is an error to register a dictionary type whose instances return <code>#t</code> to any predicate already registered.</p> <p><code>(register-dictionary-type!</code> <em>arg</em> …<code>)</code></p> @@ -242,7 +242,7 @@ that file.<p> 'dict-size alist-size 'dict-for-each alist-foreach 'dict->alist alist->alist)) -</code></blockquote> +</pre></blockquote> <h2 id="implementation">Implementation</h2> <p>The sample implementation is found in the GitHub repository.</p> |