about genricity

From: Harvey J. Stein <abel_at_netvision.net.il>
Date: Thu, 12 Sep 1996 11:47:37 +0300

Andre Gilles writes:
> Hello,
>
> I am writing a software based on classes that write and read themselves
> on files.
...
> When I want to read a class, I don't know how to do it in a clean way.
> Here is what I do
>
> (while not-eof-port
> read line on port
> if line match a regexp corresponding to child-class-1
> the create an instance of child-class-1
> (read child-class-1 port)
> if line match a regexp corresponding to child-class-2
> the create an instance of child-class-2
> (read child-class-2 port)

One trick I sometimes use is to write data out in a format which can
be read back in and executed.

For example, my (write foo) might write something like:

   (format #t "(make ~s :x ~s :y ~s)"
        (class-of foo) (x-of foo) (y-of foo))

Then, when I want to read the objects back in, I can either just load
the file, or I can read it an sexp at a time and eval each sexp.

Maybe something along these lines can help you...

Good luck,

Dr. Harvey J. Stein
Berger Financial Research
abel_at_netvision.net.il
Received on Thu Sep 12 1996 - 10:55:58 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST