[Oberon] How to mimic an associative array

Jan Verhoeven jan at verhoeven272.nl
Fri Dec 3 19:12:21 CET 2010


Hi Duke,

> decoding, splitting the data which is sent in variable_name=value
> pairs. 

I did it in Modula-2 so it can be done in Oberon as well.

> Because Perl and PHP are dynamically-typed languages, 

Nope. They are WEAKLY typed languages. They allow freedom of everything, 
thereby creating a syntax that cannot be fully understood by single 
persons. That's there are so many books about Perl/PHP.

> their respective associative arrays can hold any data-type. 

Yes and that is a feature of that language. Tcl does something similar. 
All variables are strings. Depending on the operation, the interpreter 
makes a decision what to do with a set of variables.

So 1.0 + 2.0 will result in 3.0
But 1,0 + 2,0 will result in 1,02,0

It is a feature of Tcl that makes the 'language' totally unpredictable.

The major advantage of Wirthian languages is their predictability. That 
is achieved by strict typing, strict syntax and as little keywords as 
possible. You get a lean language that can be tailored to do whatever 
you want.
The scripting languages also seem to mimmick something from Switzerland: 
the swiss army knife. The languages are so feature rich that making a 
compiler for that language becomes virtually impossible.

> I now realize that therein lies my problem, when I say that I want to
> mimic an associative array in Oberon. 

You do not NEED such a thing. You WANT one. You can do with any kind of 
data object. It's just that you will have to change your thinking. 

When in Rome, act as the romans.
When in Perl, act as the perl scripters
When in Oberon, obey the rules of the compiler.

Oberon is no Perl, Tcl, Python, PHP (is that a language?), Modula-2, 
Pascal, Algol, Ada, Fortran, BASIC.
Oberon is a type-safe, reliable, compact and fast language. It does not 
come with a million libraries for just about anything. Unless you make 
them.

> I was thinking of writing a CGILib Module which would obtain the
> contents of the CGI environment variables, and load them into an ADT

That would be no problem at all. 

> CGILib would not know in advance what data-type was being passed to
> it.

All CGI variables only output TEXT. No spaces and some control tokens as 
well. CGI variables only produce ASCII. Sometimes the ASCII is the 
representation of a number. But it still is ASCII.

> It has to be able to behave like a dynamically typed language/module.

What does this mean? 

> Is that possible in Oberon-2? 

Of course.

> I want a more abstract solution, to enjoy code re-use :) Is that
> possible in a strictly-typed language.

Yes.

Can you show what you did in Perl? Perhaps an Oberon guru can translate 
it to our Ob.

CGI is no rocket science. It's just text processing. Text input, text 
output.

-- 
Met vriendelijke groeten,

Jan Verhoeven
http://www.verhoeven272.nl



More information about the Oberon mailing list