Create a set of data types based upon inheritance. Each data type or class should have a print command that displays the contents of an instance of that class to standard output. Create instances of each class in your inheritance hierarchy and display them to standard output. Write each of the objects to a file named objects.dat in binary form using serialization or marshalling. Read the file objects.dat and print the contents of each serialized object.

include "builtins/serialize.e"
 
function randobj()
-- test function (generate some random garbage)
    object res
    if rand(10)<=3 then     -- make sequence[1..3]
        res = {}
        for i=1 to rand(3) do
            res = append(res,randobj())
        end for
    elsif rand(10)<=3 then  -- make string
        res = repeat('A'+rand(10),rand(10))
    else
        res = rand(10)/2    -- half int/half float
    end if
    return res
end function
 
object o1 = randobj(),
       o2 = randobj(),
       o3 = randobj()
 
pp({o1,o2,o3},{pp_Nest,1})
integer fh = open("objects.dat", "wb")
puts(fh, serialize(o1))
puts(fh, serialize(o2))
puts(fh, serialize(o3))
close(fh)
 
?"==="
 
fh = open("objects.dat", "rb")
?deserialize(fh)
?deserialize(fh)
?deserialize(fh)
close(fh)
{} = delete_file("objects.dat")
