Re: Structures

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

A little more elaboration on what my idea of what structures
would be like in Euphoria...

Native structures:
  These would be structures composed of Euphoria's native types.

structure my_struct_type
    integer  member1,
    atom     member2,
    sequence member3,
    object   member4
end structure

function do_stuff (my_struct_type this_struct)
    integer int1
    sequence seq1
    my_struct temp_struct
    .
    .
    .
    this_struct.member1 = int1  -- fine, as long as int1 is
                                --   initialized
    int1 = this_struct.member1  -- fine too, same condition

    this_struct.member1 = seq1  -- gives exception only with
                                --   type checking on

    this_struct = temp_struct   -- always ensures temp_struct
                                --   is of same type, with or
                                --   without type check (otherwise
                                --   the <.whatever> syntax could
                                --   get you into trouble)
                                -- member initializations are
                                --   never checked

    return this_struct          -- can be returned, just like
                                --   any other type
                                -- member initializations are
                                --   checked.
end function
-----------------------------
my_struct_type a_struct
sequence a_sequence
.
.
.
a_struct = do_stuff(a_struct)     -- since do_stuff has it's
                                  --   parameter typed as a
                                  --   structure, the variable
                                  --   passed will always be
                                  --   type-checked.
                                  --   had it specified a parameter
                                  --   as sequence or object,
                                  --   no checking would be
                                  --   done with type check off

a_sequence = do_stuff(a_sequence) -- illegal, because of
                                  --   parameter type

a_sequence = a_struct             -- fine, sequences can be
                                  --   assigned the value of an
                                  --   entire structure, so can
                                  --   objects, but never the
                                  --   other way around!

a_sequence.member1 = 1            -- illegal! sequences do NOT
                                  --   inheret the <.whatever>
                                  --   syntax, nor do objects

As Mr. Phillips suggested, having structs be flexible can be
of advantage, but that come's implicitly thru Euphoria's
flexible types. member3 or member4 could contain virtually
anything. Also by virtue of this being treated as basically
another type, you could have sequences containing structures,
giving quite a bit of flexibility there as well.

C Structures:
The example I used in my previous post was just for a special
type of structure, one for C's types that would be immediately
passable to external functions. These would by necessity be
very rigid, and could only be used for assignment and passing
to external functions, not to be generally used within the
rest of your program. (Also, the example I used in the other
post was fairly ugly, it was just what I was suggesting it do
logically, not how it should appear stylistically).

Thanks,
Christopher D. Hickman

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

Search



Quick Links

User menu

Not signed in.

Misc Menu