Re: Structures

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

At 09:59 AM 3/5/98 -0500, you wrote:
>>  C_STRUCT My_Structure
>>  {
>>    C_INT value1
>>    C_INT value2
>>    some_other_struct structure2
>>  }
>
>
>If I need a structure in Euphoria, here is what I do:
>
>constant VALUE1 = 1, VALUE2 = 2,
>         MY_STRUCTURE = 2
>
>procedure something()
>    sequence this
>    this = repeat({}, MY_STRUCTURE)
>
>    this[VALUE1] = 5
>    this[VALUE2] = 9
>    -- Code.....
>end procedure
>
>It works for me....

True, but a structure as implemented in, say, Pascal, does some
type checking, as well as making member references easier and
clearer. For example:
 PayRec = record
    name : string;
    rate : real;
    dependents : integer;
    end;

employee = PayRec;

then you can reference these fields as:
employee.name = "Joe Smith"
or pay_amount = hours * employee.rate

and you won't be able to make assignment errors such as
dependents = 3.14 or rate = "Fred"

Plus there's no need to enumerate the fields before you can reference
them, i.e.: NAME = 1, RATE = 2, DEP = 3...etc.

Awful handy, IMO. Reduces errors and makes the code shorter and clearer
(isn't that the whole idea behind Euphoria?)

Irv
----------------------------------------------------------------------------
-----------
Visit my Euphoria programming web site:
http://www.mindspring.com/~mountains
----------------------------------------------------------------------------
-----------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu