[Oberon] How to mimic an associative array

Duke Normandin dukeofperl at ml1.net
Fri Dec 3 18:23:33 CET 2010


On Fri, 3 Dec 2010, Yaroslav Romanchenko wrote:

>
> Simple implementation of string hash.

[snip]

WoW! I suspect that the code Active Oberon specific, correct? Can the
same be done in plain Oberon-2? The "context" thing is what I'm
thinking about.

I have a confession to make - I may not have explained properly the
context in which I want to use this "associative" array, hash, table,
dictionary - whatever.

I wanted/want to practice writing Oberon-2 code in context of CGI
scripts/"programs". In order to do so, I need to manipulate data sent
from HTML forms to the webserver. The vehicle used by the CG Interface
are various CGI environment variables, like QUERY_STRING, PATH_INFO,
CONTENT_LENGTH, etc. This "manipulation" involves reading, decoding,
splitting the data which is sent in variable_name=value pairs. These
pairs have historically fit well into a Perl/PHP associative array,
where the "key" was loaded with the form's variable_name, and the
"value" with what the web user typed in. Because Perl and PHP are
dynamically-typed languages, their respective associative arrays can
hold any data-type. I now realize that therein lies my problem, when I
say that I want to mimic an associative array in Oberon. I was
thinking of writing a CGILib Module which would among other things,
obtain the contents of the about CGI environment variables, and load
them into an ADT called FORM. However CGILib would not know in advance
what data-type was being passed to it. It has to be able to behave
like a dynamically typed language/module. Is that possible in
Oberon-2? or with the code that you were so kind to put together?

The alternative is for each cgi script to custom "manipulate" the CGI
environment variables and the data. The programmer would know in
advance that the form contains fields for "last_name", "first_name",
which are strings; and "age" (integer); "salary" (real). So he could
set up his CGI "manipulation" procedures with the correct data-types
_for each script_ every time.

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

I feel bad, because I should have explained myself better, and saved
you, Doug and Aubrey all that time and effort.

Much obliged...
-- 
Duke



More information about the Oberon mailing list