Re: Handling Structured Memory
- Posted by irv at take.maxleft.com Nov 13, 2002
- 408 views
On Wednesday 13 November 2002 03:42 pm, Derek wrote: > Yes Irv, I was only addressing the structed RAM issue and not the other > issue of strucured data. I agree that Euphoria would be enhanced if it > supported both concepts at the syntax level. The current method of > assigning sequence element indexes to constants and then using these is a > little kludgy. > > constant Name = 1, > Address = 2, > Telephone = 3, > SIZEOF_CUSTOMER = 3, > NewCustomer = {"","",""} > > type CustRecord (object x) > if sequence(x) and length(x) = SIZEOF_CUSTOMER and > sequence(x[Name]) and > sequence(x[Address]) and > sequence(x[Telephone]) then > return 1 > else > return 0 > end if > end type > > CustRecord TempCust > > TempCust = NewCustomer > TempCust[Name] = "Derek Parnell" > TempCust[Address] = "123 Main St" > TempCust[Telephone] = "555 5555" > > ------ > instead of a simpler ... > > struct sequence CustRecord > sequence Name > sequence Address > sequence Telephone > end struct > > CustRecord TempCust > > TempCust.Name = "Derek Parnell" > TempCust.Address = "123 Main St" > TempCust.Telephone = "555 5555" I know you understand this, but in case someone else doesn't: With the example given, even the first (standard Euphoria) method) doesn't look too clumsy. However, most data I work with has not three fields, but 80 or 100. Adding or removing a single item means renumbering as many as 99 out of 100 entries in the constant definitions. That would be easier if Rob was willing to add enum, but enum would be only a partial solution to this problem, because we'd still be stuck with having to use global constants. Meaning we could only 1. use NAME and ADDR once in the entire program, or 2. prefix everything, like customer[i][custName], customer[i][custADDR], or 3. use namespacing: customer[i][cust:NAME], customer[i][cust:ADDR]. (How many times do I have to type cust before Euphoria catches on?) Compare that with the following: with customer[i] do printf(1,"%s\n%s\n",{NAME,ADDR}) Next, think of writing code to properly initialize those 80 or 100 fields, so we don't get the "has not been assigned a value" error. Worse, consider the effort required to write and debug a 100 line type routine. Is it going to be fast? Doesn't seem likely, since every time an assignment is made to ANY member of the structure, every single member must be t;ype checked again. Regards, Irv