Re: SS

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

Karl Bochert wrote:
> 
> Having seen some of the misunderstandings, I would like to
> re-present my SS proposal in different words. Perhaps I can be clearer.
> 
> StructureS
> }}}
<eucode>
>    -- Define a structure
>    structure Point is
>       atom x, y
>    end structure
> </eucode>
{{{

> A piece of data named Point is created.
> It has 2 elements which can only be accessed by name
> The values of the elements are always initialized, to 0 if not
> otherwise specified.
> }}}
<eucode>
>    ?Point.x   --> "0.0"
>    ?Point.y   --> "0.0"
>    Point.x += 3.0
>    Point.y = Point.x + 1.0
>    ?Point.x    --> "3.0"
>    ?Point.y    --> "4.0"
> </eucode>
{{{

> The ids used for the members ( x and y) are available only in 
> the Point namespace, not globally so:
> }}}
<eucode>
>    ?Point.x   --> "3.0"
>    ?x         -- ERROR not defined
>    integer x
>    x = 1
>    ?x    --> "1"
>    ?Point.x  --> "3.0"
> </eucode>
{{{

> 
> In addition to holding some data, Point may be used as a prototype to
> create new data. It provides both the structure and the data to the new
> item.
> }}}
<eucode>
>     Point p1
>     ?p1.x    --> "3.0" 
>     ?p1.y    --> "4.0"
> </eucode>
{{{

> The newly created structure has all the attributes of a structure
> and can be used to create further structures
> }}}
<eucode>
>     p1.x = 2.0
>     p1 p2
>     ?p2.x -> "2.0"
> </eucode>
{{{

> 
> 
> -- extends
> A structure may be declared as being an extension of another, in which
> case it has all the elements of the structure being extended and any new
> items it declares
> }}}
<eucode>
>     structure Point3d extends Point
>        atom z
>     end structure
>     ?Point3d.z  --> "0.0"
>     ?Point3d.x  --> "2.0" --Point.x was set above, and copied into Point3d
> </eucode>
{{{

> 
> The not-notation is fully nestable so:
> }}}
<eucode>
>     structure color is
>       integer r, g, b
>     end structure
>     structure ColorPoint extends Point
>        color mycol
>     end structure
>     ?ColorPoint.color  --> "<0,0,0>"
>     ?ColorPoint.color.r  --> "0"
> </eucode>
{{{

> 
> Note how ColorPoint.color is printed.
> A structure is NOT a sequence!
> 
> KtB

I actually quite like this idea too.

I see you could have structures within structures.

Under this definition, could you have a sequence contain structures?
eg
-- Define a structure
   structure Point is
      atom x, y
   end structure

sequence my_sequence
my_sequence = repeat(Point, 10)

my_sequence[5].x = 4


ie, arrays

Chris


http://euallegro.wikispaces.com
http://members.aol.com/chriscrylex/euphoria.htm
http://uboard.proboards32.com/
http://members.aol.com/chriscrylex/EUSQLite/eusql.html

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

Search



Quick Links

User menu

Not signed in.

Misc Menu