[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-janitors] #1290: Unit srfi-69: does not specify action when two
From: |
Chicken Trac |
Subject: |
[Chicken-janitors] #1290: Unit srfi-69: does not specify action when two merged hash tables contain the same keys |
Date: |
Thu, 26 May 2016 16:46:13 -0000 |
#1290: Unit srfi-69: does not specify action when two merged hash tables contain
the same keys
------------------------+---------------------
Reporter: nxg | Owner:
Type: defect | Status: new
Priority: minor | Milestone: someday
Component: extensions | Version: 4.10.x
Keywords: srfi-69 |
------------------------+---------------------
The documentation for `hash-table-merge` says
(hash-table-merge HASH-TABLE-1 HASH-TABLE-2) procedure
Returns a new HASH-TABLE with the union of HASH-TABLE-1 and HASH-
TABLE-2.
However this does not specify which hash table 'wins' when the two hash
tables contain the same key. This procedure doesn't appear in SRFI 69, so
that doesn't resolve it.
From experiment, and by inspection of the code, it is clear that hash-
table-1 wins:
{{{
% csi
CHICKEN
(c) 2008-2015, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.10.0 (rev b259631)
macosx-unix-clang-x86-64 [ 64bit manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)
#;1> (use srfi-69)
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/srfi-69.import.so
...
; loading library srfi-69 ...
#;2> (define h1 (alist->hash-table '((a . 1) (x . 2))))
#;3> (define h2 (alist->hash-table '((b . 1) (x . 3))))
#;4> (define h3 (hash-table-merge h1 h2))
#;5> (hash-table->alist h3)
((x . 2) (b . 1) (a . 1))
#;6>
}}}
But it would be good to document this, so that the user can know this is
not an unspecified behaviour which may change in future. The same goes
for
{{{
(alist->hash-table '((a . 1) (a . 2)))
}}}
Does this produce a hash table with `a` defined as 1 or 2 (it's 1, but the
documentation doesn't guarantee this)
----
Incidentally (and at the risk of putting distinct notes into one ticket),
it would be really attractive if this library defined a pure-functional
`hash-table-set` which mapped `(hash-table? any any) -> hash-table?`
--
Ticket URL: <http://bugs.call-cc.org/ticket/1290>
CHICKEN Scheme <http://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-janitors] #1290: Unit srfi-69: does not specify action when two merged hash tables contain the same keys,
Chicken Trac <=