Re: Structs
- Posted by begin Jun 17, 2019
- 4594 views
well here is my version and sorry i am bad at explaining.
Define some dummy structures for demonstration of my imagination: a structure can contain all primitve datatypes for ex.
struct dummy_struct_t atom a1, sequence s1, -- sequence s2, object o1, integer i1, string s1, wstring sw1, $
Structure fields may not be initialized within the struct. some structs:
struct dummy_struct_1 atom a1, object o1, $ struct dummy_struct_2 atom a2, object o2, integer i2, $
define some new structure with a structure variable used in it
struct container_struct atom crap1, sequence scrap1, dummy_struct_1 st1, $
now we have a structure that is extended and contains a structure for ex.
struct e_c_s_1 extend dummy_struct_2 atom crap1, sequence scrap1, dummy_struct_1 st1, $
e_c_s_1 now contains (inherited) the fields of structure dummy_struct_2 and a struct variable dummy_struct_1. This I think could be maybe a future single inheritance thing just like Oberon uses it. Since we are not shooting for classes, forward procedure or function declarations are not allowed in the structure. Oberon would give you the possibility for something like that for ex.
struct xxx_1 extend dummy_struct_2 atom x, sequence crap1, struct dummy_struct_1, function average(atom a, atom b), -- function signature procedure plot(integer x, integer y, integer char=‘*‘), -- procedure signature $
declaring and using a structure for ex.
global e_c_s_1 x -- or can use the private attribute or initialized for ex. global (private) e_c_s_1 x = {1.0,{5,1.5},{{5.0,"3"}}} -- or global (private) e_c_s_1 x = {1.0,{5,1.5}} -- here the dummy_struct_1 part is initializes by the compiler to {} ...
using struct in procedures or functions
function plot(e_c_s_1 x, integer y, integer char=‘*‘) -- the default value for e_c_s_1 x could be {} or some other legal initializer s. obove, -- or initializers are forbidden in signatures container_struct y = {0.1, {}, {1.5,"x"}} or container_struct y y.crap1=0.1 y.scrap1={{},5,1.5} y.st1.a1=0.1 y.st1.o1="ddddd" position(x.y, y.crap1) puts(1, char) return {y.crap1, y.st1, y} end function
i guess i get slapped now.