Eu improvements (part 3)

new topic     » topic index » view thread      » older message » newer message

Allow the programmer to defined one fixed sequence in terms of another.

sequence Point is
        integer x, y
    end sequence

    sequence Point_3D extends Point
        integer z
    end sequence


If at some later time we decide that a Point should have a name, we
can change the definition of Point to
sequence Point is
        sequence name
        integer x, y
    end sequence

and a Point_3D gets a name field automatically (it is a Point, after all)

Some notes:
'Point' provides 5 things:
1) an actual sequence
2) Access to elements by name (with dot notation)
3) A separate namespace for the element names
4) A user defined type that provides type checking just like Eu's
    current type() mechanism
5) Extension from parents (Inheritance)


The data typing aspect can be understood by realizing that Eu
can already create the Point datatype (so 'without typecheck' acts just
as it does for any other user-defined type)
type Point (sequence s)
        if length(s) != 2 then return 0 end if
        if not integer[1] then return 0 end if
        if not integer[2] then return 0 end if
        return 1
    end type


One fine point is to realize that the Point datatype serves as a
prototype for the definition of new sequences -- it creates them complete
with data:
sequence Point is
        integer x, y
    end sequence
    Point.x = 5

    Point my_point  -- create my_point as a copy of Point
    ? my_point    -- => '5' 

The newly created sequence is initialized.

KtB

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu