[racket] Reading in data structures from files (specifically structs)

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Tue Dec 13 23:12:27 EST 2011

Structs are generative, so this won't work.

Prefab structs are probably what you want here.

Vincent


At Tue, 13 Dec 2011 22:05:40 -0600,
Todd Bittner wrote:
> 
> [1  <multipart/alternative (7bit)>]
> [1.1  <text/plain; ISO-8859-1 (7bit)>]
> I'm trying to do something like the following:
> 
> I create a struct, say (struct foo (bar baz) #:transparent), where bar is a
> string and baz is an integer, and then write - using write, not display -
> several instances of the struct to a file.  When I inspect the file, it
> looks something like this:
> 
> #(struct:foo "string1" 1)
> #(struct:foo "string2" 2)
> 
> When I read this back in to my program, I get an s-exp back that is
> '#(struct:foo "string1" 1).  When I eval it, it's still '#(struct:foo
> "string1" 1), and calling (foo?) on it returns #f.  Is there someway that I
> can reconstitute this back into a foo struct?
> 
> Thanks.
> [1.2  <text/html; ISO-8859-1 (quoted-printable)>]
> 
> [2  <text/plain; us-ascii (7bit)>]
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.