Re: Eu improvements (part 4)
- Posted by ags <eu at 531pi.co.nz> Jan 07, 2007
- 648 views
Chris Bensler wrote: > Actually, while data structures would be useful too, I don't think that is > what > we are actually in need of. What we need is a way to address the global > pollution > created by all the index constants used for the pseudo-structures we already > use routinely. We just need a way to name the elements. Yes, I thought that too after reading Robert's old post. I think an enum-like syntax would help a lot there, but they become another data type too. eg
enum customer_record = ID, first_name, last_name, balance -- create a sequence of length 4 sequence customer as customer_record -- I don't actually like this idea though as you have to tie the variable to something else -- or alternatively -- sequence customer customer = repeat(0, length(customer_record)) -- number of enums -- or -- constant enumLength = customer_record -- the name of the enum itself returns its length -- customer = repeat("", enumLength) -- ie (but looks odd) -- -- customer = repeat("", customer_record) customer.ID = next_ID() customer[first_name] = "Bob" customer.balance = 10000 -- and of course customer[3] = "Smith" -- would still work -- calling the enum like a function with the name of record you want returns -- the index of the field. integer balance_field balance_field = customer_record(balance) customer[balance_field] -= 400
I do like the idea of named data access to sequences with dot notation but anything that helps with the field access will help, without having to define 100 constants for every type of 'structure' you are trying to create. I know these wouldn't go anywhere near what people were talking about the last week or so but it might be easier to implement? Gary