[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

record type not safely stored

From: Judy Hawkins
Subject: record type not safely stored
Date: Sun, 1 Feb 2009 18:05:24 -0800 (PST)


I wanted to create records that would remain available throughout a
guile session, but they get stepped on in some way I don't know how
to fix.

See the bottom of this file for a complete guile session illustrating
the bug.


(use-modules (ice-9 rdelim))

(define (wl s) (write-line s))

(define r:type (make-record-type "good-rec" '(laugh sleep)))
(define r:type? (record-predicate r:type))
(define r:constr (record-constructor r:type))

(define  r:g:laugh (record-accessor r:type (string->symbol "laugh")))
(define  r:s:laugh (record-modifier r:type (string->symbol "laugh")))
(define  r:g:sleep (record-accessor r:type (string->symbol "sleep")))
(define  r:s:sleep (record-modifier r:type (string->symbol "sleep")))

(define (make-r1)
  (let* (
         (r1 (r:constr "giggle" "dream"))
    r1  ;;; return it so I can try to keep it around

(if (not (defined? (string->symbol "Keep-r1")))
    (define Keep-r1 #f))

(define (keep-record-around)
  (if (not Keep-r1)
      (set! Keep-r1 (make-r1))
      (wl "Keep-r1 already has the record"))

(wl "Good record?")
(wl (r:type? Keep-r1))
(wl Keep-r1)

 guile session: load rb.scm twice, see if Keep-r1 has a valid record.

 $ guile

 guile> (load "rb.scm")
 Good record?
 #<good-rec laugh: giggle sleep: dream>

 guile> (r:g:laugh Keep-r1)

 guile> (load "rb.scm")
 Keep-r1 already has the record
 Good record?
 #<good-rec laugh: giggle sleep: dream>

 guile> (r:g:laugh Keep-r1)

 ERROR: In procedure %record-type-check:
 ERROR: Wrong type record (want `"good-rec"'): #<good-rec laugh: giggle sleep: 
 ABORT: (wrong-type-arg)

 what I expected was for (r:g:laugh Keep-r1) to work fine both times.

 Other types such as strings and procedures treated the same way work
 as I expected them to.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]