Structures

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

On a different subject from the namespace stuff... What about structures?
I know they were mentioned a few weeks ago, but I feel that structures
will make a lot of my code more readable and faster.

-- I don't usually use 'type' so if this doesn't work right... Ignore it.
type file(integer x)
    return file >= -1
end type

structure coord
    integer x
    integer y
end structure

structure foobar
    integer foo
    file bar    -- Supports other stuff, of course!
    coord pos   -- Other structures can be used, of course also!
end structure

foobar qwerty

qwerty.foo = 5
qwerty.bar = -5   -- Won't work! type file must be -1 or more!

printf(1, "%d\n", {qwerty.foo})

Currently, I am doing this:

-- Structure foobar
constant FOO = 1, BAR = 2,
         FOOBAR_FIELDS = 2
sequence qwerty
qwerty = repeat({}, FOOBAR_FIELDS)

qwerty[FOO] = 5
qwerty[BAR] = -5  -- This shouldn't be able to work, but nothing can be
done
                  -- done about that . . .

printf(1, "%d\n", {qwerty[FOO]})

This isn't so bad, but I find myself needing a whole bunch of structures,
and then I start to get naming conflicts...

-- Structure coord
constant X = 1, Y = 2

-- Structure player
constant NAME = 1, HP = 2, X = 3, Y = 4  -- Oops! X and Y are already
defined!

-- Do this instead:
constant NAME = 3, HP = 4  -- X = 1, Y = 2

-- But what about this? Structure inventory:
-- NAME = 1, VALUE = 2  -- NAME is already defined, but it doesn't need
the
                        -- other stuff, just these two!


But I have already had instances where there are too many conflicts to
easily resolve by simply renumbering everything.

I don't know how hard this will be to actually impliment into Euphoria,
but I know it will be easy to code in, and won't break existing code, and
still is simple and easy to understand...

Any reason this couldn't be done eventually?

(Else is there some easy way to fix the problems I'm having?)

Sometime (A few months from now) I want to convert Descent into Euphoria,
seeing as the source code has been released..... All I need is to hope
the Euphoria Assembly language translator holds through it's ASM
code..... Me not knowing how to use Assembly and all....... :) Anyway,
since as I can use the code for non commercial purposees (can't charge
any money for it, and shouldn't ask for donations), and it has been
released, I thought a Euphoria version would be nice, but it uses
structures also and converting them into the constants will just be more
trouble . . . (There, isn't that a good reason to have structures? :)

Just my 1 cent. I dropped the other one and can't find it.... :)

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

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

Search



Quick Links

User menu

Not signed in.

Misc Menu