* bug#11196: missing constructor procedure in new srfi-9 records
@ 2012-04-07 19:54 Klaus Stehle
2012-04-09 21:21 ` Ludovic Courtès
2012-04-09 22:19 ` Ludovic Courtès
0 siblings, 2 replies; 3+ messages in thread
From: Klaus Stehle @ 2012-04-07 19:54 UTC (permalink / raw)
To: 11196
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#11196: missing constructor procedure in new srfi-9 records
2012-04-07 19:54 bug#11196: missing constructor procedure in new srfi-9 records Klaus Stehle
@ 2012-04-09 21:21 ` Ludovic Courtès
2012-04-09 22:19 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2012-04-09 21:21 UTC (permalink / raw)
To: Klaus Stehle; +Cc: 11196
Hi Klaus,
Klaus Stehle <klaus.stehle@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’.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#11196: missing constructor procedure in new srfi-9 records
2012-04-07 19:54 bug#11196: missing constructor procedure in new srfi-9 records Klaus Stehle
2012-04-09 21:21 ` Ludovic Courtès
@ 2012-04-09 22:19 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2012-04-09 22:19 UTC (permalink / raw)
To: Klaus Stehle; +Cc: 11196-close
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’.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-09 22:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-07 19:54 bug#11196: missing constructor procedure in new srfi-9 records Klaus Stehle
2012-04-09 21:21 ` Ludovic Courtès
2012-04-09 22:19 ` 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).