1. Elegant structures

If you recall, Rob said he wants to find a way to impliment structures
elegantly. After giving it some thought, I figured that structures have a
LOT of different things that need to be addressed.

So far, the discussion has been pretty much limited to how they would be
created and accessed in general. We need to figure out how structures should
be used in every aspect. In C, for example, the structure is basically a
pointer to the structure, and an offset to access the data. (Plus another
offset if used as an array.) This allows all kind of neat tricks for saving
to disk. smile (If you have an idea of what you're doing, of course. blink

So, here's where we figure out how each of the things structures can do will
be done. Maybe Rob can't think of elegant ways to do everything, so if all
over 230 of us do, then it'll be a lot easier for him to add them!

-- Simple structure
structure pos_struct
   atom x, y
end structure

-- More advanced
structure test
   atom a
   integer i
   sequence s
   object x
   pos_struct pos
end structure

-- Create them
sequence test my_var  -- Setup my_var as a sequence
test owie -- This can't be used as a sequence

-- Ok, so how do we initialize the structure? Comments?
my_var = {} -- Need better way!
owie = {}

-- Once initialized, we access it
? my_var[5].x -- Works
? owie[50].x -- Doesn't work (owie isn't a sequenced structure)
? my_var.x -- Doesn't work
? owie.x -- works.

-- Disk access. In C, we just take the pointer and place
-- sizeof(my_var) bytes to disk, starting at the pointer. We want
-- something that simple, too! smile
print(fn, my_var) -- Something like this to save to disk?
my_var = get(fn) -- Load from disk somehow!

-- What would this do?
? my_var
? my_var[1]

-- Currently, we can do my_var[5][POS][X..Y] = {5, 5}, how
-- would this be done? Probably, it wouldn't, unless:
pos_struc data
data.x = 1
data.y = 2
my_var[3].pos = data -- Would this work?


Well, those are the issues I can think of. Let's try to add more and then
resolve them.

new topic     » topic index » view message » categorize

2. Re: Elegant structures

> -- Simple structure
> structure pos_struct
>    atom x, y
> end structure
>
> -- More advanced
> structure test
>    atom a
>    integer i
>    sequence s
>    object x
>    pos_struct pos
> end structure
>
> -- Create them
> sequence test my_var  -- Setup my_var as a sequence

I suggest putting in an of keyword, so this would be changed to sequence of test
my_var or something. It would be a lot more readable and it would make it easier
for interperters to read (otherwise it might read it as:
sequence test
my_var
)

And put in classes. They are very elegant, in my opinion; especially if we were
to Euphorize them.

--
Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu