[Oberon] string manipulation

spir denis.spir at gmail.com
Tue Jun 22 12:27:53 MEST 2010


I'm an amateur programmer, completely new to Oberon. Is this a proper place to find help in learning the *language*; and to talk about it?

If yes, I have a first question: strings are defined as sequences of characters. But this only seems to define pieces of text in literal notation; there is I guess no corresponding type. If I get it correctly, then we are supposed to store and manipulate strings in ARRAYs OF CHAR, which will automatically be 0-terminated:
"If an expression e of type Te is assigned to a variable v of type Tv, the following happens:
if Tv is ARRAY n OF CHAR and e is a string of length m <n, v[i] becomes ei for i = 0..m -1 and v[m] becomes 0X. "

But this type is a bit unhandy, esp in the fact it cannot be RETURNed.
How are we supposed to deal with strings concretely? For instance, how can I write a procedure text intended to allow outputing a Position:

MODULE aTrial;

	Position = RECORD
		x	: INTEGER;
		y	: INTEGER;

PROCEDURE (VAR pos:Position) text() : ???;
    RETURN ???; (* "x:pos.x,y:pos.y" *)

VAR pos : Position;

    pos.x := 1; pos.y := 2;
    (* write pos.text to stdout *);
END aTrial.

If there is no builtin way to handle strings practically, how can one build a custom tool (a type) for this? I'm aware I could use POINTER TO ARRAY OF CHAR to pass strings around (*), but then I need to explicitely (de)reference all strings.

Another point about strings is the common need to output variable values (for examples, prototyping, testing...). Maybe it's only me beeing blind, but I cannot even find builtin tools to output atomic values... not to evoke arrays or records.


(*) Like in the example Trees module at §11 of the Oberon-2 language report.

vit esse estrany ☣


More information about the Oberon mailing list