[Oberon] How to mimic an associative array

Chris Burrows chris at cfbsoftware.com
Sun Dec 5 00:37:38 CET 2010


> -----Original Message-----
> From: Jan Verhoeven [mailto:jan at verhoeven272.nl] 
> Sent: Sunday, 5 December 2010 5:43 AM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] How to mimic an associative array
> 
> > I followed the discussion for a while, and up to now saw
> > TWO different solutions to your original question:
> 
> Neither of which even comes close to the associative array.
> 

To be fair the subject of this discussion is "How to MIMIC an associative
array".

If you really wanted to use an array you could implement a function (e.g.
Idx) that returned an INTEGER hash value given a string and then write e.g.

 capital[Idx("England")] := "London";
 location := capital[Idx("England")];


> And let's be glad things are the way Niklaus made them. What would be 
> next? Arrays whose indexes were floating point numbers?
>

I agree with you there. I recall many years ago reading the report of a new
language (it may have been Ada or Modula-3) that allowed floating point
numbers in FOR loops. I didn't read any further.

A similar argument to why you should / should not be able to use strings as
array selectors pops up in the Delphi newsgroups every few months and
results in much heated debate. In this case it is usually triggered by
somebody thinking what a great idea it would be to be able to use strings as
CASE statement selectors e.g.

CASE country OF:
  "Australia": capital := "Canberra" |
  "England":   capital := "London" |
  "France":    capital := "Paris" |
...
...

(I hope I haven't opened up a new can of worms by mentioning this!)

Basically there are two main groups:

1) Those who believe the language should encourage the writing of efficient
code by not providing facilities that produce inefficient code. You can
develop inefficient code if you really want to but you have to work much
harder to get it.

2) Those who believe the language and compiler's job is to reduce the amount
of thinking and writing the programmer has to do and it doesn't matter how
inefficient the resulting code is.

I belong to group 1.

> 
> Probaby I'm old fashioned.
> 

Only if you still shave with a cut-throat razor, prefer to write letters
using pen and paper, and believe that vinyl sounds better than CDs ;-)

Regards,
Chris

Chris Burrows
CFB Software
Astrobe v3.2 ARM Oberon-07 Development System
http://www.astrobe.com





More information about the Oberon mailing list