Changes between Version 2 and Version 3 of TablesCowan


Ignore:
Timestamp:
08/27/10 09:47:28 (7 years ago)
Author:
cowan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TablesCowan

    v2 v3  
    1313Incorporating this proposal as a standard feature in WG1 Scheme implementations makes it possible to write efficient and portable programs that use tables. 
    1414 
     15I have added equivalences to SRFI-69 (Basic hash tables) where they exist.  Names are based on those in CompleteSequenceCowan. 
     16 
    1517== Constructors == 
    1618 
    1719`(make-table `[''equivalence-function'']` . `''args''`)` 
    1820 
    19 Creates a new table with no associations. ''Equivalence-function'' is a predicate that should accept two keys and return a boolean telling whether they denote the same key value; it defaults to `equal?`. 
     21Creates a new table with no associations. ''Equivalence-function'' is a predicate that should accept two keys and return a boolean telling whether they denote the same key value; it defaults to `equal?`.  (SRFI-69 `make-hash-table`) 
     22 
    2023 
    2124Implementations MAY use the ''args'' for implementation-specific extensions. 
     
    2326`(table `[''key'' ''value''] ... `)` 
    2427 
    25 Creates a new table and populates it with the associations based on the successive ''key'' and ''value'' arguments.  The implementation may take the arguments into account in deciding which what kind of table to create.  
     28Creates a new table and populates it with the associations based on the successive ''key'' and ''value'' arguments.  The implementation may take the arguments into account in deciding what kind of table to create, but should not assume that no other types of keys or values will ever exist.   (Not in SRFI-69) 
    2629 
    27 `(list->`''table''` `''alist'' . `''args''`)` 
     30`(list->table` `''alist'' . `''args''`)` 
    2831 
    29 Creates a new table which maps the car of every element in ''alist'' to the cdr of the same element.  The ''args'' are interpreted as in `make-table`. If some key occurs multiple times in alist, the value in the first association will take precedence over later ones.  
     32Creates a new table as if by invoking `(make-table . `''args''`)` which maps the car of every element in ''alist'' to the cdr of the same element.  If some key occurs multiple times in alist, the value in the first association will take precedence over later ones.  (SRFI-69 `alist->hash-table`) 
    3033 
    3134`(table-copy `''table''`)` 
    3235 
    33 Creates a new table with the same equivalence predicate, associations, and implementation-dependent properties (if any) as ''table''. 
     36Creates a new table with the same equivalence predicate, associations, and implementation-dependent properties (if any) as ''table''. (SRFI-69 `hash-table-copy`) 
    3437 
    3538== Predicates == 
    3639 
    37 `(table? `''obj''`)` 
     40`(table? `''obj''`)`  
    3841 
    39 Returns `#t` if ''obj'' is a table. 
     42Returns `#t` if ''obj'' is a table.  (SRFI-69 `hash-table?`) 
    4043 
    41 `(table-exists? `''table''` `''key''`)' 
     44`(table-key-exists? `''table''` `''key''`)` 
    4245 
    43 Returns `#t` if there is any association to ''key'' in ''table''. 
     46Returns `#t` if there is any association to ''key'' in ''table''. (SRFI-69 `hash-table-exists?`) 
    4447 
    4548== Accessors == 
     
    4750`(table-ref `''table''` `''key'' [ ''thunk'' ]`)` 
    4851 
    49 Returns the value associated to ''key'' in ''table''. If no value is associated to ''key'' and ''thunk'' is given, it is called with no arguments and its value is returned; if ''thunk'' is not given, an error is signalled. 
     52Returns the value associated to ''key'' in ''table''. If no value is associated to ''key'' and ''thunk'' is given, it is called with no arguments and its value is returned; if ''thunk'' is not given, an error is signalled.  (SRFI-69 `hash-table-ref`) 
    5053 
    5154`(table-length `''table''`)` 
    5255 
    53 Returns the number of associations in table. 
     56Returns the number of associations in ''table''.  (SRFI-69 `hash-table-size`) 
    5457 
    5558`(table-keys `''table''`)` 
    5659 
    57 Returns a list of the keys in ''table''. The order of the keys is unspecified. 
     60Returns a list of the keys in ''table''. The order of the keys is unspecified.  (SRFI-69 `hash-table-keys`) 
    5861 
    5962`(table-values`''table''`)` 
    6063 
    61 Returns a list of the values in ''table''. The order of the keys is unspecified, and may be inconsistent with the results of `table-keys`. 
     64Returns a list of the values in ''table''. The order of the keys is unspecified, and may be inconsistent with the results of `table-keys`.  (SRFI-69 `hash-table-values`) 
    6265 
    6366`(table-equivalence-function `''table`)` 
    6467 
    65 Returns the equivalence function of ''table''. 
     68Returns the equivalence function of ''table''.  (SRFI-69 `hash-table-equivalence-function`) 
    6669 
    6770== Mutators == 
     
    6972`(table-set! `''table''` `''key''` `''value''`)` 
    7073 
    71 Sets the ''value'' associated to ''key'' in ''table''. The previous association (if any) is removed. 
     74Sets the ''value'' associated to ''key'' in ''table''. The previous association (if any) is removed.  (SRFI-69 `hash-table-set!`) 
    7275 
    7376`(table-delete! `''table''` `''key''`)` 
    7477 
    75 Removes any association to ''key'' in ''table''. It is not an error if no association for that ''key'' exists; in this case, nothing is done. 
     78Removes any association to ''key'' in ''table''. It is not an error if no association for that ''key'' exists.  (SRFI-69 `hash-table-delete!`) 
    7679 
    77 `(table-update! `''table''` `''key''` `''function'' [ ''thunk'' ]`)` 
     80`(table-update! `''table''` `''key''` `''procedure'' [ ''thunk'' ]`)` 
    7881 
    7982Semantically equivalent to, but may be implemented more efficiently than, the following code: 
    8083 
    81 `(table-set! `''table''` `''key''` (function (table-ref `''table''` `''key''` `''thunk''`)))` 
     84`(table-set! `''table''` `''key''` (`''procedure'' `(table-ref `''table''` `''key''` `''thunk''`)))` 
     85 
     86(SRFI-69 `hash-table-update!`) 
    8287 
    8388== Iterators == 
     
    8590`(table-map `''table''` `''procedure'' . `''args''`)` 
    8691 
    87 Returns a new table as if by invoking `(make-table . `''args''`).  The new table is the result of mapping ''procedure'', which takes two arguments, over ''table''.  It is applied to the key and value of each association in ''table'', and returns two values, the key and value to be placed in the new table. 
     92Returns a new table as if by invoking `(make-table . `''args''`).  The new table is the result of mapping ''procedure'', which takes two arguments, over ''table''.  It is applied to the key and value of each association in ''table'', and returns two values, the key and value to be placed in the new table.  (Not in SRFI-69) 
    8893 
    8994`(table-for-each `''table''` `''procedure''`)` 
    9095 
    91 The same as `table-map`, except that no new table is constructed; returns undefined values. 
     96The same as `table-map`, except that no new table is constructed; returns undefined values.  (SRFI-69 `hash-table-walk`) 
    9297 
    9398`(table->list `''table''`)` 
    9499 
    95 Returns an association list such that the car of each element is a key in ''table'' and the corresponding cdr of is the value associated to the key.  The order of the elements is unspecified. 
     100Returns an association list such that the car of each element is a key in ''table'' and the corresponding cdr of is the value associated to the key.  The order of the elements is unspecified.  (SRFI-69 `hash-table->alist`)