unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Immutable rnrs hashtable
@ 2012-11-25 23:00 Sjoerd van Leent Privé
  2012-11-26  1:07 ` Ian Price
  2012-11-26  1:25 ` Ian Price
  0 siblings, 2 replies; 7+ messages in thread
From: Sjoerd van Leent Privé @ 2012-11-25 23:00 UTC (permalink / raw
  To: guile-devel

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.

Can someone check this?

Regards,
Sjoerd



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-25 23:00 Immutable rnrs hashtable Sjoerd van Leent Privé
@ 2012-11-26  1:07 ` Ian Price
  2012-11-26  1:25 ` Ian Price
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Price @ 2012-11-26  1:07 UTC (permalink / raw
  To: Sjoerd van Leent Privé; +Cc: guile-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=iso-2022-jp-2, Size: 2070 bytes --]

Sjoerd van Leent Priv^[$(D+1^[(B <svanleent@gmail.com> 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"



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-25 23:00 Immutable rnrs hashtable Sjoerd van Leent Privé
  2012-11-26  1:07 ` Ian Price
@ 2012-11-26  1:25 ` Ian Price
  2012-11-26  9:44   ` Sjoerd van Leent Privé
  2012-11-26 16:34   ` Ludovic Courtès
  1 sibling, 2 replies; 7+ messages in thread
From: Ian Price @ 2012-11-26  1:25 UTC (permalink / raw
  To: Sjoerd van Leent Privé; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]


Whoops, in my haste, I forgot to note that this _is_ a bug in guile's
documentation, not in the implementation. Suggested fix included.

Ludovic, Andy:
Should I add him to THANKS too?

-- 
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"


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: docs patch --]
[-- Type: text/x-patch, Size: 972 bytes --]

From 085552d83d647a05b8ab33810ce50401d0f3afe4 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Mon, 26 Nov 2012 01:24:51 +0000
Subject: [PATCH] Fix docs for `hashtable-copy'

* doc/ref/r6rs.texi (rnrs hashtables): a true mutable argument means a
  mutable copy.
---
 doc/ref/r6rs.texi |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/ref/r6rs.texi b/doc/ref/r6rs.texi
index f9bc9e9..2028ada 100644
--- a/doc/ref/r6rs.texi
+++ b/doc/ref/r6rs.texi
@@ -2101,8 +2101,8 @@ immutable.
 @deffn {Scheme Procedure} hashtable-copy hashtable
 @deffnx {Scheme Procedure} hashtable-copy hashtable mutable
 Returns a copy of the hash table @var{hashtable}.  If the optional
-argument @var{mutable} is a true value, the new hash table will be
-immutable.
+argument @var{mutable} is provided and is a true value, the new hash
+table will be mutable.
 @end deffn
 
 @deffn {Scheme Procedure} hashtable-clear! hashtable
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-26  1:25 ` Ian Price
@ 2012-11-26  9:44   ` Sjoerd van Leent Privé
  2012-11-26 10:28     ` Ian Price
  2012-11-26 16:34   ` Ludovic Courtès
  1 sibling, 1 reply; 7+ messages in thread
From: Sjoerd van Leent Privé @ 2012-11-26  9:44 UTC (permalink / raw
  To: Ian Price; +Cc: guile-devel

Hi Ian,

The implementation is okay, I wrote a half baked example, as I 
understood the bit to be the mutable field. But it should act in 
reverse. Got it. In many cases, I use info-lookup-symbol in Guile's 
documentation, as it is much easier to navigate than the RNRS website 
(which I consider bad design, as there is no sensible hierarchy 
whatsoever or something of a decent index).

This is why I got it wrong, as the documentation was mistaken, and I did 
the opposite of what I should be doing. And yes, I was using #t and #f, 
But I expected the results to be the other way around.

Btw, isn't their a hashtable which is more pure in it's implementation? 
The RNRS and SRFI-69 versions are having quite some side-effects. I 
would have expected a method like "hashtable-add" which copies an 
existing hashtable, adds values and returns a new hashtable. I know, I 
prefer pure functional implementations...

Sjoerd

On 11/26/2012 02:25 AM, Ian Price wrote:
> Whoops, in my haste, I forgot to note that this _is_ a bug in guile's
> documentation, not in the implementation. Suggested fix included.
>
> Ludovic, Andy:
> Should I add him to THANKS too?
>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-26  9:44   ` Sjoerd van Leent Privé
@ 2012-11-26 10:28     ` Ian Price
  2012-11-26 14:18       ` Sjoerd van Leent Privé
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Price @ 2012-11-26 10:28 UTC (permalink / raw
  To: Sjoerd van Leent Privé; +Cc: guile-devel

Sjoerd van Leent Privé <svanleent@gmail.com> writes:

> Btw, isn't their a hashtable which is more pure in it's
> implementation? The RNRS and SRFI-69 versions are having quite some
> side-effects. I would have expected a method like "hashtable-add"
> which copies an existing hashtable, adds values and returns a new
> hashtable. I know, I prefer pure functional implementations...

You could look up vhashes in the manual. Alternatively, if your data
has an ordering you can use (pfds bbtrees) from my pfds collection[0]


0. https://github.com/ijp/pfds or guild install pfds
-- 
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"



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-26 10:28     ` Ian Price
@ 2012-11-26 14:18       ` Sjoerd van Leent Privé
  0 siblings, 0 replies; 7+ messages in thread
From: Sjoerd van Leent Privé @ 2012-11-26 14:18 UTC (permalink / raw
  To: Ian Price; +Cc: guile-devel

Hi Ian,

Thanks for the suggestions. I will certainly have a look at those. I 
believe the bbtrees can come in handy. Can certainly give it a go.

Sjoerd

On 11/26/2012 11:28 AM, Ian Price wrote:
> Sjoerd van Leent Privé <svanleent@gmail.com> writes:
>
>> Btw, isn't their a hashtable which is more pure in it's
>> implementation? The RNRS and SRFI-69 versions are having quite some
>> side-effects. I would have expected a method like "hashtable-add"
>> which copies an existing hashtable, adds values and returns a new
>> hashtable. I know, I prefer pure functional implementations...
> You could look up vhashes in the manual. Alternatively, if your data
> has an ordering you can use (pfds bbtrees) from my pfds collection[0]
>
>
> 0. https://github.com/ijp/pfds or guild install pfds




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Immutable rnrs hashtable
  2012-11-26  1:25 ` Ian Price
  2012-11-26  9:44   ` Sjoerd van Leent Privé
@ 2012-11-26 16:34   ` Ludovic Courtès
  1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2012-11-26 16:34 UTC (permalink / raw
  To: guile-devel

Hi!

Ian Price <ianprice90@googlemail.com> skribis:

> Whoops, in my haste, I forgot to note that this _is_ a bug in guile's
> documentation, not in the implementation. Suggested fix included.

Good catch, please push!

> Ludovic, Andy:
> Should I add him to THANKS too?

That’s a good idea in general, yes.

Ludo’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-11-26 16:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-25 23:00 Immutable rnrs hashtable Sjoerd van Leent Privé
2012-11-26  1:07 ` Ian Price
2012-11-26  1:25 ` Ian Price
2012-11-26  9:44   ` Sjoerd van Leent Privé
2012-11-26 10:28     ` Ian Price
2012-11-26 14:18       ` Sjoerd van Leent Privé
2012-11-26 16:34   ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).