1. EUPHORIA struct support

Forked from C Struct Support

mattlewis said...

Now that 4.0 is out, it's time to start thinking about...4.1! In fact, there is a wiki page with a high level overview of what's being planned:

EuphoriaRoadmap

One of the items on that list is for support for dealing with C-style structures in memory (not to be confused with data structures of native euphoria objects). Anyone who has dealt with an external API has probably needed to deal with these, managing offsets and data formats, peeking and poking...The goal is to make all of this easier for the euphoria programmer.

Matt

That's going to be really useful for interfacing with C libraries and most of them are written in C. To write the same thing in EUPHORIA for sequences we have to create an enumerated list of constants. Wouldn't it be good to have something similar for sequences?

struct sequence person  
    integer magic 
    sequence name 
    sequence phone_numbers 
end struct 
 
person p1 
p1.magic = "Person" 
p1.name = "Matt Lewis" 
p1.phone_numbers = {} 
-- The following prints 
-- Person 
-- Matt Lewis 
-- 
for i = 1 to length(p1) do 
   ? p1[i] 
end for 
new topic     » topic index » view message » categorize

2. Re: EUPHORIA struct support

SDPringle said...

Forked from C Struct Support

mattlewis said...

Now that 4.0 is out, it's time to start thinking about...4.1! In fact, there is a wiki page with a high level overview of what's being planned:

EuphoriaRoadmap

One of the items on that list is for support for dealing with C-style structures in memory (not to be confused with data structures of native euphoria objects). Anyone who has dealt with an external API has probably needed to deal with these, managing offsets and data formats, peeking and poking...The goal is to make all of this easier for the euphoria programmer.

Matt

That's going to be really useful for interfacing with C libraries and most of them are written in C. To write the same thing in EUPHORIA for sequences we have to create an enumerated list of constants. Wouldn't it be good to have something similar for sequences?

struct sequence person  
    integer magic 
    sequence name 
    sequence phone_numbers 
end struct 
 
person p1 
p1.magic = "Person" 
p1.name = "Matt Lewis" 
p1.phone_numbers = {} 
-- The following prints 
-- Person 
-- Matt Lewis 
-- 
for i = 1 to length(p1) do 
   ? p1[i] 
end for 

Ignoring the special functionality of ?, we already have this. Mostly, this would be syntax sugar on top of sequences (and as a case in point, this syntax is already implemented by dot4).

I suppose, that there is some benefit from being able to use the same syntax for both C structs and "Euphoria structs", but your proposal seems to be moving in the opposite direction.

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

3. Re: EUPHORIA struct support

the downside about dot4
(even though i use it a lot)
is that the enum/constants used
for field access are namespace bound

i can see the merits of declaring a
structure and binding it to type

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

4. Re: EUPHORIA struct support

by namespace bound,
i mean that your enums/contants
have to be carefully named so as
to avoid clashes

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

5. Re: EUPHORIA struct support

struct sequence person  
    integer magic 
    sequence name 
    sequence phone_numbers 
end struct 
 
person p1 
p1.magic = "Person" 
p1.name = "Matt Lewis" 
p1.phone_numbers = {} 
-- The following prints 
-- Person 
-- Matt Lewis 
-- 
for i = 1 to length(p1) do 
   ? p1[i] 
end for 

What you seem to be suggesting here is yet another enum scheme that incorporates type checking as well, that's assuming that assigning "Person" to the magic integer would result in an error.

One of the major selling points for Euphoria is the simplicity of the language; very few keywords/built-in functions. When I first ran across Euphoria years ago I learned the entire language in an afternoon, including reading the REFMAN.DOC and reviewing the include libraries. With version 4 I am seeing the complexity starting to grow. Not bad yet, but if it continues unabated it won't be very long before Euphoria is competing with Java and C+ for complexity.

I'm not sure you need both enum and struct in the language, but I have thought from day 1 it would be nice to have type checking when assigning something to a sequence (that includes user defined types).

Specific comments on the example code follows.

I think it should read "struct person" unless you think there will be "struct integer" and "struct atom", etc.

The name space concept already uses the . notation I would be more in favor of p1[magic] = "Person".

I would extend that concept to p1 = {"Person", "Matt Lewis", {}} where type checks would occur on each element of p1 assigned.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu