On Wed, 8 Dec 2010 16:13:08 -0500
Matthias Felleisen <matth...@ccs.neu.edu>
wrote:


> ;;
> ----------------------------------------------------------------------------- 
> ;;
> usage example (could be separate module) (define detail-default "?")
> (struct/kw book (author title [details detail-default]) #:transparent)
> 
> (define book1 (book/kw #:title "The Client" #:author "John Grisham"))
> 
> (define book2 (book/kw #:title "The Client" #:author "John Grisham"
> #:details "?"))
> 
> (string=? (book-author book1) "John Grisham") 
> (string=? (book-details book2) "?")
> 
> 

If for instance I write book1 to a file (using write) and read it back
using read this works fine. 

However, if I then try to use it as a struct/kw this will fail.
Example:

(call-with-output-file "books" 
        (lambda (out) (write book1 out)))

; works fine
(define bookx (call-with-input-file "books" 
      (lambda (in) (read in))))

; gives error
(string=? (book-author book1) (book-author bookx))


book-author: expects argument of type <struct:book>; given
'#(struct:book "John Grisham" "The Client" "")

 === context ===
/usr/lib/racket/collects/racket/private/misc.rkt:85:7


Indeed they are different:

> book1
(book "John Grisham" "The Client" "")
> bookx
'#(struct:book "John Grisham" "The Client" "")


Can this be solved within the definition of struct/kw or do I have to
work around it.



-- 
Manfred






-- 
Manfred


_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to