Re: about genricity

From: David Fox <fox_at_graphics.cs.nyu.edu>
Date: 11 Sep 1996 11:18:52 -0400

In article <3236824A.12C6EC0C_at_crs.etca.fr> Andre Gilles <andre_at_crs.etca.fr> writes:

] 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)
] ...
]
] Each time I create another heir of parent-class I have to modify this
] code. I find that this sequence of "if" is against the spirit of
] polymorphism but I can't manage to find another way to do it. Is there a
] classic way to handle such problems ?
]
] Gilles
]

Your output function could write scheme code to re-create the object,
like this:

        (begin
          (require "child-class-1")
          (make <child-class-1> args...))

you could read it using something like this:

        (define restored-child-1 (eval (read port)))
-- 
David Fox	   http://found.cs.nyu.edu/fox		xoF divaD
NYU Media Research Lab   fox_at_cs.nyu.edu    baL hcraeseR aideM UYN
Received on Wed Sep 11 1996 - 17:29:13 CEST

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