From: Klaus Stehle <klaus.stehle@uni-tuebingen.de>
To: 11198@debbugs.gnu.org
Subject: bug#11198: problems reading data with a "read-hash-extend" registered reader
Date: Sat, 7 Apr 2012 22:16:06 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.61.1204072212190.6107@commlink.zdv.uni-tuebingen.de> (raw)
Hi,
;;;; an example script to describe the problem
;;;; writing and reading records:
(use-modules (srfi srfi-9))
;; define a record as example
(define-record-type my-record
(make-my-record one two)
my-record?
(one my-one)
(two my-two))
;; fix another guile-2.0 bug
(if (string>= (version) "2")
(struct-set! my-record (+ 2 vtable-offset-user) make-my-record))
;; the record write function
(define (record-printer s p)
(let* ((rtd (record-type-descriptor s))
(lst (apply append
(map (lambda (f) (list (symbol->keyword f)
((record-accessor rtd f) s)))
(record-type-fields rtd)))))
(format p "#R~S" (cons (record-type-name rtd) lst))))
(struct-set! my-record vtable-index-printer record-printer)
;; the record read function
(define (read-R chr port)
(let ((rlst (read port)))
(if (not (pair? rlst))
#f
(let* ((name (car rlst))
(lst (cdr rlst))
(rtd (primitive-eval name))
(fields (record-type-fields rtd)))
(apply (record-constructor rtd)
(map (lambda (f) (let ((kl (memq (symbol->keyword f)
lst)))
(if (and kl (pair? (cdr kl)))
(cadr kl)
#f))) fields))))))
(read-hash-extend #\R read-R)
;; test-1: writing and reading records is working well ...
(define rec (make-my-record "bla" "bobo"))
(let ((opo (open-output-file "rec.data")))
(write rec opo)
(close-output-port opo))
(let ((ipo (open-input-file "rec.data")))
(let ((data (read ipo)))
(format #t "--> ~S~%" rec)
(close-input-port ipo)))
;; test-2: ... but this doesn't work properly
(define rec #R(my-record #:two "bobo" #:one "bla"))
(format #t "==> ~S~%" rec)
;; end of script
The behavour of test-2 is very strange. If the script is running
from a file, there is a compiler error message, but the record is built
and displayed.
If we start the script with the -l option and enter the line
afterwards manually into the REPL ...
(define rec #R(my-record #:two "bobo" #:one "bla"))
... there is another cryptic error message:
=> While compiling expression:
=> ERROR: build-constant-store: unrecognized object
#R(my-record #:one "bla" #:two "bobo")
We can see our record built correctly in the error message! But the record
remains unreachable.
Using guile-1.8 all these things are running perfectly!
Cheers,
Klaus Stehle
----------------------------
guile --version
guile (GNU Guile) 2.0.5
uname -srm
Linux 2.6.32-5-amd64 x86_64
next reply other threads:[~2012-04-07 20:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-07 20:16 Klaus Stehle [this message]
2012-04-09 21:10 ` bug#11198: problems reading data with a "read-hash-extend" registered reader Ludovic Courtès
2012-04-11 19:07 ` Klaus Stehle
2012-04-11 19:33 ` Mark H Weaver
2012-04-11 20:34 ` Klaus Stehle
2012-04-22 13:43 ` Mark H Weaver
2012-04-22 18:01 ` Ludovic Courtès
2012-04-24 8:11 ` Andy Wingo
2012-04-24 11:24 ` Noah Lavine
2012-04-24 11:38 ` Noah Lavine
2012-04-24 16:22 ` Ludovic Courtès
2012-07-05 8:00 ` bug#11198: prefab structs in guile Andy Wingo
[not found] ` <877gui7i3y.fsf@pobox.com>
2012-07-05 20:57 ` Ludovic Courtès
[not found] ` <87ipe2dizn.fsf@gnu.org>
2012-07-05 21:06 ` Andy Wingo
[not found] ` <878vex534f.fsf@pobox.com>
2012-07-05 21:55 ` Ludovic Courtès
[not found] ` <874npldga9.fsf@gnu.org>
2012-07-05 22:03 ` Andy Wingo
2012-07-05 22:06 ` Andy Wingo
[not found] ` <87ipe13lya.fsf@pobox.com>
2012-07-05 22:14 ` Ludovic Courtès
[not found] ` <87a9zdc0tc.fsf@gnu.org>
2012-11-27 21:52 ` Ludovic Courtès
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=Pine.LNX.4.61.1204072212190.6107@commlink.zdv.uni-tuebingen.de \
--to=klaus.stehle@uni-tuebingen.de \
--cc=11198@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).