unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#11198: problems reading data with a "read-hash-extend" registered reader
@ 2012-04-07 20:16 Klaus Stehle
  2012-04-09 21:10 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Klaus Stehle @ 2012-04-07 20:16 UTC (permalink / raw)
  To: 11198

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





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

end of thread, other threads:[~2012-11-27 21:52 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-07 20:16 bug#11198: problems reading data with a "read-hash-extend" registered reader Klaus Stehle
2012-04-09 21:10 ` 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

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).