guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Immutable rnrs hashtable


From: Ian Price
Subject: Re: Immutable rnrs hashtable
Date: Mon, 26 Nov 2012 01:07:38 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Sjoerd van Leent Priv$(D+1(B <address@hidden> writes:

> Hi all,
>
> I might have found an issue using commit
> 06906f370f77cbab520ff0d3c47449526934a9c8 (stable-2.0). I am attempting
> to do a hashtable-copy using rnrs hashtables, and set the mutable flag
> to #:t (according to documentation this should make it immutable, a
> bit odd). I attempted #:f as well. It appears the output hashtable is
> still mutable.

Firstly, according to the R6RS, if the mutable argument is provided, and
is true, then the hashtable is mutable. Otherwise it is immutable.
http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-14.html#node_idx_1200

Secondly, #f or #:f ? #:f is a keyword, and since it isn't #f, is considered a
true value. Therefore, the hashtable should be mutable.

A quick repl transcript

scheme@(guile$B!](Buser)> (make-eqv-hashtable)
$10 = #<r6rs:record:r6rs:hashtable>
scheme@(guile$B!](Buser)> (hashtable-set! $10 'foo 'bar)
scheme@(guile$B!](Buser)> (hashtable-copy $10 #t)
$11 = #<r6rs:record:r6rs:hashtable>
scheme@(guile$B!](Buser)> (hashtable-ref $11 'foo #f)
$12 = bar
scheme@(guile$B!](Buser)> (hashtable-set! $11 'baz 'zot)
scheme@(guile$B!](Buser)> (hashtable-copy $10 #f)
$13 = #<r6rs:record:r6rs:hashtable>
scheme@(guile$B!](Buser)> (hashtable-ref $13 'foo #f)
$14 = bar
scheme@(guile$B!](Buser)> (hashtable-set! $13 'baz 'zot)
scheme@(guile$B!](Buser)> (hashtable-ref $13 'baz #f)
$15 = #f
scheme@(guile$B!](Buser)> (hashtable-mutable? $11)
$16 = #t
scheme@(guile$B!](Buser)> (hashtable-mutable? $13)
$17 = #f

and, it appears to that the mutable argument works as expected. $13 is
not mutable, and it does not add an association for 'baz when I tried
it. The only concern I have is that it fails silently, however, since
the r6rs doesn't say anything about the behaviour of hashtable-set! and
hashtable-update! on immutable hashtables, this would be allowed.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]