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

From: Phil Rand (philrand at gmail.com)
Date: Sun Sep 30 14:05:00 EDT 2007

Thanks!

The serialize.ss library will work just fine for me.  I think I've
come across it before, but was scared off by its complexity arising
from its generality.   Of course that generality is exactly what I was
asking for, even though I was only thinking about my very simple
application.

Phil

On 9/30/07, Richard Cleis <rcleis at mac.com> wrote:
> 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
>
>


-- 
Phil Rand
philrand at pobox.com


Posted on the users mailing list.