unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Hartwig <mandyke@gmail.com>
To: 10621@debbugs.gnu.org
Subject: bug#10621: Incorrect usage of hash procedures in (ice-9 mapping)
Date: Thu, 29 Nov 2012 00:32:09 +0800	[thread overview]
Message-ID: <CAN3veRdF2JneERZbyAQPK0X7sm4SBbeTY6A4e=a75WLHRKA1CA@mail.gmail.com> (raw)
In-Reply-To: <87pq2x201w.fsf@gmail.com>

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

On 28 November 2012 23:56, Daniel Hartwig <mandyke@gmail.com> wrote:
> A short module, it is not hard to fix

I was after a ten minute distraction, so tackled this.  See attached.

[-- Attachment #2: 0001-fix-and-update-ice-9-mapping.patch --]
[-- Type: application/octet-stream, Size: 5332 bytes --]

From 30a4722e4453738a45c6d26201c33856dfb4dab9 Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
Date: Thu, 29 Nov 2012 00:17:26 +0800
Subject: [PATCH] fix and update (ice-9 mapping)

* module/ice-9/mapping.scm (mapping-create-handle!): INIT is required.
  (mapping-ref): Rewrite.  Fix problem with DFLT.
  (hash-table-mapping-hooks): Drop DELETE-PROC, hash-table accessors
  only use ASSOC-PROC.  Add INIT to create-handle hook.  Use correct
  hash-table accessors.
  (make-hash-table-mapping): Drop DELETE-PROC.
  (hash-table-mapping): Rewrite.  Drop DELETE-PROC.
---
 module/ice-9/mapping.scm |   77 +++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 45 deletions(-)

diff --git a/module/ice-9/mapping.scm b/module/ice-9/mapping.scm
index 2907a8d..74e98e7 100644
--- a/module/ice-9/mapping.scm
+++ b/module/ice-9/mapping.scm
@@ -50,16 +50,15 @@
 
 (define (mapping-get-handle map key)
   ((mapping-hooks-get-handle (mapping-hooks map)) map key))
-(define (mapping-create-handle! map key . opts)
-  (apply (mapping-hooks-create-handle (mapping-hooks map)) map key opts))
+(define (mapping-create-handle! map key init)
+  ((mapping-hooks-create-handle (mapping-hooks map)) map key init))
 (define (mapping-remove! map key)
   ((mapping-hooks-remove (mapping-hooks map)) map key))
 
-(define (mapping-ref map key . dflt)
+(define* (mapping-ref map key #:optional dflt)
   (cond
-   ((mapping-get-handle map key)	=> cdr)
-   (dflt				=> car)
-   (else				#f)))
+   ((mapping-get-handle map key) => cdr)
+   (else dflt)))
 
 (define (mapping-set! map key val)
   (set-cdr! (mapping-create-handle! map key #f) val))
@@ -70,18 +69,18 @@
   (let ((wrap (lambda (proc) (lambda (1st . rest) (apply proc (mapping-data 1st) rest)))))
 
     (perfect-funcq 17
-		   (lambda (hash-proc assoc-proc delete-proc)
-		     (let ((procs (list hash-proc assoc-proc delete-proc)))
+		   (lambda (hash-proc assoc-proc)
+		     (let ((procs (list hash-proc assoc-proc)))
 		       (cond
-			((equal? procs `(,hashq ,assq ,delq!))
+			((equal? procs `(,hashq ,assq))
 			 (make-mapping-hooks (wrap hashq-get-handle)
 					     (wrap hashq-create-handle!)
 					     (wrap hashq-remove!)))
-			((equal? procs `(,hashv ,assv ,delv!))
+			((equal? procs `(,hashv ,assv))
 			 (make-mapping-hooks (wrap hashv-get-handle)
 					     (wrap hashv-create-handle!)
 					     (wrap hashv-remove!)))
-			((equal? procs `(,hash ,assoc ,delete!))
+			((equal? procs `(,hash ,assoc))
 			 (make-mapping-hooks (wrap hash-get-handle)
 					     (wrap hash-create-handle!)
 					     (wrap hash-remove!)))
@@ -90,39 +89,27 @@
 					      (lambda (table key)
 						(hashx-get-handle hash-proc assoc-proc table key)))
 					     (wrap
-					      (lambda (table key)
-						(hashx-create-handle hash-proc assoc-proc table key)))
+					      (lambda (table key init)
+						(hashx-create-handle! hash-proc assoc-proc table key init)))
 					     (wrap
 					      (lambda (table key)
-						(hashx-get-handle hash-proc assoc-proc delete-proc table key)))))))))))
-
-(define (make-hash-table-mapping table hash-proc assoc-proc delete-proc)
-  (make-mapping (hash-table-mapping-hooks hash-proc assoc-proc delete-proc) table))
-
-(define (hash-table-mapping . options)
-  (let* ((size (or (and options (number? (car options)) (car options))
-		   71))
-	 (hash-proc (or (kw-arg-ref options #:hash-proc) hash))
-	 (assoc-proc (or (kw-arg-ref options #:assoc-proc)
-			 (cond
-			  ((eq? hash-proc hash) assoc)
-			  ((eq? hash-proc hashv) assv)
-			  ((eq? hash-proc hashq) assq)
-			  (else (error 'hash-table-mapping
-				       "Hash-procedure specified with no known assoc function."
-				       hash-proc)))))
-	 (delete-proc (or (kw-arg-ref options #:delete-proc)
-			  (cond
-			   ((eq? hash-proc hash) delete!)
-			   ((eq? hash-proc hashv) delv!)
-			   ((eq? hash-proc hashq) delq!)
-			   (else (error 'hash-table-mapping
-					"Hash-procedure specified with no known delete function."
-					hash-proc)))))
-	 (table-constructor (or (kw-arg-ref options #:table-constructor)
-				(lambda (len) (make-vector len '())))))
-    (make-hash-table-mapping (table-constructor size)
-			     hash-proc
-			     assoc-proc
-			     delete-proc)))
-
+						(hashx-remove! hash-proc assoc-proc table key)))))))))))
+
+(define (make-hash-table-mapping table hash-proc assoc-proc)
+  (make-mapping (hash-table-mapping-hooks hash-proc assoc-proc) table))
+
+(define* (hash-table-mapping #:optional (size 71) #:key
+                             (hash-proc hash)
+                             (assoc-proc
+                              (or (assq-ref `((,hashq . ,assq)
+                                              (,hashv . ,assv)
+                                              (,hash . ,assoc))
+                                            hash-proc)
+                                  (error 'hash-table-mapping
+                                         "Hash-procedure specified with no known assoc function."
+                                         hash-proc)))
+                             (table-constructor
+                              (lambda (len) (make-vector len '()))))
+  (make-hash-table-mapping (table-constructor size)
+                           hash-proc
+                           assoc-proc))
-- 
1.7.10.4


  reply	other threads:[~2012-11-28 16:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-27  8:25 bug#10621: Incorrect usage of hash procedures in (ice-9 mapping) Mark H Weaver
2012-11-28 15:56 ` Daniel Hartwig
2012-11-28 16:32   ` Daniel Hartwig [this message]
2013-02-24 14:10   ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN3veRdF2JneERZbyAQPK0X7sm4SBbeTY6A4e=a75WLHRKA1CA@mail.gmail.com' \
    --to=mandyke@gmail.com \
    --cc=10621@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).