Re: Structures; etc.
- Posted by Lee West <leewest at ALTAVISTA.COM> Jan 31, 2000
- 506 views
Hi All, I've been following the recent commentary on structures and OOP, especially as it relates to preprocessors. Personally, I don't understand some of the concerns that invoking these techniques via a preprocessor would somehow negatively impact Euphoria's processing speed... or cause the "type" command to be used. I have put together a simple example of a record structure that could be processed by a preprocessor and the Euphoria code that would result. It certainly doesn't require that the "type" command be used, therefore, I can't see where the performance degradation would occur. As to whether this is preferable or even desirable... I'll let you decide. But it does present an alternative to the, so called, MISSING language elements of Euphoria, without the performance penalties that may occur if they were incorporated into the Eu code itself. I believe an implementation of this type is completely feasible, and can even see the possibility of a full implementation of an OOP option as well. I'd love to hear your thoughts. The example follows: ----------------------- -- Define a record type record Employee Phone integer -- This is an embeded record type in the Employee record record Name First string Last string end record Amount real WeeklyCnt array[1..4] of integer end record -- Define a record variable of the type Employee eeRecord Employee -- Define a pointer to the record RecNo pointer -- Create a new instance of the record type RecNo = eeRecord.New -- Populate the new record using DOT notation eeRecord[RecNo].Phone = 1112223333 eeRecord[RecNo].Name.First = "John" eeRecord[RecNo].Name.Last = "Doe" eeRecord[RecNo].Amount = 1000.00 eeRecord[RecNo].WeeklyCnt[1] = 25 -- Create another instance of the record type RecNo = eeRecord.New -- Populate the new record eeRecord[RecNo].Phone = 2223334444 eeRecord[RecNo].Name.First = "Jane" eeRecord[RecNo].Name.Last = "Doe" eeRecord[RecNo].Amount = 2000.75 eeRecord[RecNo].WeeklyCnt[3] = 25 -------------------------------------------- -- PreProcess the above code and generate -- -- the following Euphoria code -- -------------------------------------------- -- Define the variables sequence temp, eeRecord constant Phone = 1, Name = 2, NameFirst = 1, NameLast = 2, Amount = 3, WeeklyCnt = 4 -- Define the record counter integer RecNo RecNo = 0 -- Initialize the record and record template eeRecord = {} temp = {0,{"",""},0.0,{0,0,0,0}} -- Based on the record definition -- Populate the first eeRecord eeRecord = append(eeRecord,temp) RecNo += 1 eeRecord[RecNo][Phone] = 1112223333 eeRecord[RecNo][Name][NameFirst] = "John" eeRecord[RecNo][Name][NameLast] = "Doe" eeRecord[RecNo][Amount] = 1000.00 eeRecord[RecNo][WeeklyCnt][1] = 25 -- Populate another occurrence of the eeRecord eeRecord = append(eeRecord,temp) RecNo += 1 eeRecord[RecNo][Phone] = 2223334444 eeRecord[RecNo][Name][NameFirst] = "Jane" eeRecord[RecNo][Name][NameLast] = "Doe" eeRecord[RecNo][Amount] = 2000.75 eeRecord[RecNo][WeeklyCnt][3] = 15 -- Print the record include print.e print(1,eeRecord) -- The following is printed -- {{1112223333,{"John","Doe"},1000,{25,0,0,0}},{2223334444, {"Jane","Doe"},2000.75,{0,0,15,0}}} Thanks. Lee.