GNU bug report logs - #11196
missing constructor procedure in new srfi-9 records

Previous Next

Package: guile;

Reported by: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>

Date: Sat, 7 Apr 2012 20:02:02 UTC

Severity: normal

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11196 in the body.
You can then email your comments to 11196 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#11196; Package guile. (Sat, 07 Apr 2012 20:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 07 Apr 2012 20:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>
To: bug-guile <at> gnu.org
Subject: missing constructor procedure in new srfi-9 records
Date: Sat, 7 Apr 2012 21:54:34 +0200 (CEST)
Hi,

;;;; A short example script to describe the problem:

(use-modules (srfi srfi-9))

;; A simple record definition for example
(define-record-type my-record
  (make-my-record one two)
  my-record?
  (one my-one)
  (two my-two))

;; "Normal" construction is working well
(define r1 (make-my-record "1" "2"))

;; This should also work, but it doesn't!
(define r2 ((record-constructor my-record) "1" "2"))
=> ERROR

;; Where's the constructor procedure?
(display (record-constructor my-record)) (newline)

=> #f


The bug is located in the new srfi-9.scm which forgets to set the
record's constructor procedure.
The following patch may help (hoping not to introduce new problems):



--- srfi-9.scm  2012-04-06 16:52:02.000000000 +0200
+++ srfi-9.scm  2012-04-06 17:14:36.000000000 +0200
@@ -188,7 +188,9 @@
        (let* ((fields      (field-identifiers #'(field-spec ...)))
               (field-count (length fields))
               (layout      (string-concatenate (make-list field-count 
"pw")))
-              (indices     (field-indices (map syntax->datum fields))))
+              (indices     (field-indices (map syntax->datum fields)))
+              (ctor-proc   (syntax-case #'constructor-spec ()
+                             ((func args ...) (syntax func)))))
          #`(begin
              (define type-name
                (let ((rtd (make-struct/no-tail
@@ -204,7 +206,7 @@
                     (eq? (struct-vtable obj) type-name)))

              #,(constructor #'type-name #'constructor-spec indices)
-
+             (struct-set! type-name (+ 2 vtable-offset-user) #,ctor-proc)
              #,@(accessors #'type-name #'(field-spec ...) indices)))))))

 ;;; srfi-9.scm ends here




Cheers,
Klaus Stehle


----------------------------
guile --version
guile (GNU Guile) 2.0.5

uname -srm
Linux 2.6.32-5-amd64 x86_64




Information forwarded to bug-guile <at> gnu.org:
bug#11196; Package guile. (Mon, 09 Apr 2012 21:23:02 GMT) Full text and rfc822 format available.

Message #8 received at 11196 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>
Cc: 11196 <at> debbugs.gnu.org
Subject: Re: bug#11196: missing constructor procedure in new srfi-9 records
Date: Mon, 09 Apr 2012 23:21:09 +0200
Hi Klaus,

Klaus Stehle <klaus.stehle <at> uni-tuebingen.de> skribis:

> (use-modules (srfi srfi-9))
>
> ;; A simple record definition for example
> (define-record-type my-record
>   (make-my-record one two)
>   my-record?
>   (one my-one)
>   (two my-two))
>
> ;; "Normal" construction is working well
> (define r1 (make-my-record "1" "2"))
>
> ;; This should also work, but it doesn't!
> (define r2 ((record-constructor my-record) "1" "2"))
> => ERROR

The use of ‘record-constructor’ above relies on a implementation detail
of the SRFI-9 implementation in Guile 1.8–namely, that SRFI-9 records
were implemented in terms of “Guile records” (info "(guile) Records").

In Guile 2.0, SRFI-9 records are no longer “Guile records”, so they no
longer have a “record-type descriptor” attached.  Thus,
‘record-constructor’ cannot be used with them.

Since you are using SRFI-9 anyway, I would recommend sticking to the
mechanisms specified by SRFI-9, thus avoiding ‘record-constructor’.

How would it work for you?

Thanks,
Ludo’.




Reply sent to ludo <at> gnu.org (Ludovic Courtès):
You have taken responsibility. (Mon, 09 Apr 2012 22:21:02 GMT) Full text and rfc822 format available.

Notification sent to Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>:
bug acknowledged by developer. (Mon, 09 Apr 2012 22:21:03 GMT) Full text and rfc822 format available.

Message #13 received at 11196-close <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>
Cc: 11196-close <at> debbugs.gnu.org
Subject: Re: bug#11196: missing constructor procedure in new srfi-9 records
Date: Tue, 10 Apr 2012 00:19:12 +0200
Hi Klaus,

Please forget my previous message.  SRFI-9 in Guile 2.0 _is_ actually
implemented in terms of “Guile records”.  So I applied a patch similar
to yours as commit 5ef102cc93a4f2eba0f5dad94a7306085b353000.

Thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 08 May 2012 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 356 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.