[plt-scheme] How to write and read structs?

From: Richard Cleis (rcleis at mac.com)
Date: Sun Sep 30 13:04:43 EDT 2007

In the help desk, you can "Find docs for: serialize" to lead you to  
Chapter 43 of PLT MzLib: Libraries Manual.

rac

On Sep 29, 2007, at 7:23 PM, Phil Rand wrote:

> I'd like to write a list of structs to a file, then read it back,  
> and then
> access the structs as structs, not as vectors.  What am I missing?
>
> Do I need to write a vector to struct converter?
>
> Here's an example:
>
> ;; test.scm
>
> (define-struct point (x y) #f)
> (with-output-to-file "test.txt"
>   (lambda () (write (list (make-point 0 1) (make-point 1 0))))
>   'replace)
>
> (define (points)
>   (let ((stuff '()))
>     (with-input-from-file "test.txt"
>       (lambda ()
>         (set! stuff (read))))
>     stuff))
>
> (car (points))
> --> #(struct:point 0 1)
>
> (point? (car (points)))
> --> #f
>
> -- 
> Phil Rand
> philrand at pobox.com
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.