[Oberon] string manipulation
Douglas G. Danforth
danforth at greenwoodfarm.com
Wed Jun 23 01:10:15 MEST 2010
You can only return pointers from PROCEDUREs
(or primitive data types, such as INTEGER, REAL, etc.).
RECORDs and ARRAYs are not allowed. You need to think
about memory allocation to appreciate that.
If one implements
String = POINTER TO ARRAY OF CHAR;
Text = RECORD string: String END;
then one can crate a method for Text to output its string
PROCEDURE (VAR text: Text) Out, NEW;
and also a way to set the string
PROCEDURE (VAR text: Text) Set (IN x: ARRAY OF CHAR), NEW;
and then do
VAR text: Text;
N.B. Component Pascal (a superset of Oberon-2) needs the "NEW" attribute
on a method.
I don't remember whether Oberon-2 requires this or not.
Other than that the two languages are the same for this example.
> Thank, this makes things clearer. Now, since I'm a bit blocked in low-level details, I would be glad to watch an implementation of a string *type* (similar to those in most Pascal variants, for instance) in any Oberon implementation.
> In fact, the issue is that even if I can build a string type to manipulate strings, it is unusable in practice since no builtin function/procedure can use it, eg:
> I thus need an additional method to return the char sequence itself:
> But such a method cannot exist since it would have to return an ARRAY OF CHAR. ;-) the impression of beeing lost inside a vicious circle.
> Side-questions (playing the devil's advocate):
> * Rationale to forbid using open arrays as variables or return values?
> * Why no dynamic array in Oberon?
> * Or even true flexible arrays like the ones data types like lists are commonly based on?
More information about the Oberon