Re: Structs

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

It is gentler to extend ideas that we already have (less learning, simpler) then to invent a complete new "struct" syntax.

simplest case

A "struct" is a kind of "enum".

struct point X, Y, $ 

What you get is local enums `X` and `Y` for exclusive use in dot notation

point mydot 
mydot.X = 3 
mydot.Y = 5 
 
? mydot 
    --> {3,5} 

Simple and convenient. The sequence `mydot` is free to have any data-values and any kind of changes. The names `X` and `Y` can be freely used in alternative local scopes. Classic Euphoria freedom.


adapt existing user `type`

A "struct" is a special case of user "type".

An extension of the existing `user data-type`. Use it with or without type-checking. This adds the convenience of dot-notation.

type point( object x ) 
 
    struct 
        integer X, 
        atom Y, 
        string s, 
        $ 
 
    return true 
end type 
 
point mydot 
 
mydot.X = 4 
mydot.Y = 8 
mydot.s = "blue" 
 
? mydot 
--> { 4, 8, "blue" } 
 
? point( {2,3} ) 
--> false 

This way both kinds of "struct" could co-exist. The simple form could be used most of the time in general programming. The user-type version when you need rigor.

_tom

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

Search



Quick Links

User menu

Not signed in.

Misc Menu