SS

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

Having seen some of the misunderstandings, I would like to
re-present my SS proposal in different words. Perhaps I can be clearer.

StructureS
-- Define a structure
   structure Point is
      atom x, y
   end structure

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.
?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"

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


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.
Point p1
    ?p1.x    --> "3.0" 
    ?p1.y    --> "4.0"

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



-- 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
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


The not-notation is fully nestable so:
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"


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

KtB

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

Search



Quick Links

User menu

Not signed in.

Misc Menu