Re: Handling Structured Memory

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Wednesday 13 November 2002 03:05 pm, Kat wrote:

> > If anyone does not understand what I am saying here, please let me know.
> > I can post a typical example.
>
> Please post it. I stopped using Pascal partly because i couldn't nest var
> records at any place i wanted. If you want restrictions in a program,
> that's *easy* to add. It's getting the language to *allow* things that is
> difficult!

Gladly. But this has nothing at all to do with restrictions that I want to 
impose on Euphoria. It does illustrate some of features that should be 
expected in any language, but which do not exist in Euphoria:

I have a client who sells items on a time-payment plan.
To keep track of who bought what, who owes how much, etc. he needs the 
following data for each of a couple thousand customers:

for each customer, filed by ssn, the following fields:
    customer
             name, addr, city, state, zip, phone
     customer's employer 
             name, addr, city, state, zip, phone, contact
     Reference 
             name, addr, city, state, zip, phone
      Purchases     -- repeats n times
              date, item, quantity, price    
      Payments   -- repeats 24 times
              date  amount ck# 
      Adjustments -- repeats n times, for late fees, credits, etc.
              date   type   amount    ref#
      (some more stuff)

Now, to describe the structure of this data as a Pascal record would be 
pretty simple, except that you would have to establish a max value for n. 

type address_rec = record
   name : string;
   addr  : string;
   city   : string;
   state : string[2];
    zip   : string[10[;
    phone : string[10]
 end;

customer_rec = record
     ssn = string[[11];
     info = address_rec
end;

reference_rec = address_rec;

employer_rec = record
   info      = address_rec;
   contact = string
 end;

purchase_rec = record
  date :  string;
  item  : string;
  quantity : integer;
  price : real
end;

..etc...
Then to make up my customer record:

CustomerRecord = record
  customer : customer_rec;
   employer : employer_rec;
   reference : reference_rec;
   purchase : array[1..n] of purchase_rec;
    ....etc...
end;

var this_rec : CustomerRecord;

Accessing members of the structure would be simple:
When customer #1002 changes her phone number, I can read record #1002, and 
access it as:
  this_rec.customer.info.phone := "555-1212";
  
if her employer changes, it's:
 with this_rec.employer.info do
    name := "Smith Co."
    addr := "Whatever"
    phone := "555-1234"
  end;

This is simple. Compare it to trying to identify the fields in an equivalent 
Euphoria sequence by using constants.  Remember that the constants will
need to be global, because you may need to access this record from 
other routines in different source files.

Add to that the fact that Pascal will type check the members of a field. 
That saves a lot of headaches.

That's enough for now. Hope my Pascal isn't too wrong. And remember, this is 
a simple one to convert to Euphoria, because it uses so many near-identical 
structures. I'm usually not that lucky.

Regards,
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu