[Oberon] string manipulation

Aubrey.McIntosh at Alumni.UTexas.Net Aubrey.McIntosh at Alumni.UTexas.Net
Tue Jun 22 15:37:03 MEST 2010


I made some small changes, and produced this code that runs on the
Oberon V4 system.  Compile the text, and then MM click on the command
aTrial.Do  The output appears in the System Log.



MODULE aTrial;
IMPORT Out;

TYPE
       Position = RECORD
               x       : INTEGER;
               y       : INTEGER;
       END;

VAR pos : Position;

PROCEDURE (VAR pos:Position) text() ;
BEGIN
   Out.Char("(");
   Out.Int (pos.x, 1);
   Out.String (", ");
   Out.Int (pos.y, 1);
   Out.Char(")")
END text;

PROCEDURE Do*;
BEGIN
	Out.String("aTrial.Do ");
	pos.text;
	pos.x := 51;
	pos.y := 79;
	pos.text;
	Out.Ln;
	Out.String("Done.");
	Out.Ln
END Do;

BEGIN
   pos.x := 1; pos.y := 2;
END aTrial.Do

On Tue, Jun 22, 2010 at 7:24 AM, Stauber  Sven Philipp
<sven.stauber at inf.ethz.ch> wrote:
> Hi,
>
>> ... learning the *language*; and to talk about it?
>
> Be sure you don't miss the A2 Programming Quickstart Guide (http://www.ocp.inf.ethz.ch/wiki/Documentation/Language). Also, there is an Oberon & Active Oberon board on our forum (http://www.ocp.inf.ethz.ch/forum/). On http://www.oberon.ethz.ch/bibliography/publications you'll find some "Programming in Oberon" books. Last but not least, there is a lot of code around...
>
>> If yes, I have a first question: strings are defined as sequences of characters...
>
> Actually, there are several ways how strings are represented. The simplest one is ARRAY OF CHAR for ASCII strings or UTF-8 encoded strings. In A2, the text system represents characters as LONGINT (Unicode) and strings therefore as ARRAY OF LONGINT.
>
>> ... which will automatically be 0-terminated
>
> No, not automatically. It is implementation specific whether some "string" manipulation functions always result in a new "string" (0X-terminated character sequence) or not.
>
> I suggest that you have a quick look on the following modules:
>
> Strings.Mod (ASCII string manipulation)
> KernelLog.Mod (For "debug" output)
> Streams.Mod (StringReader & StringWriter, for command output that can be redirected)
>
> Also, for UTF8 and Unicode: Texts.Mod TextUtilities.Mod UTF8Strings.Mod
>
> Best,
> Sven
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: oberon-bounces at lists.inf.ethz.ch [mailto:oberon-bounces at lists.inf.ethz.ch] Im Auftrag von spir
> Gesendet: Dienstag, 22. Juni 2010 12:28
> An: oberon
> Betreff: [Oberon] string manipulation
>
> Hello,
>
>
> 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;
> IMPORT Out;
>
> TYPE
>        Position = RECORD
>                x       : INTEGER;
>                y       : INTEGER;
>        END;
>
> PROCEDURE (VAR pos:Position) text() : ???;
> VAR t : ARRAY OF CHAR;
> BEGIN
>    RETURN ???; (* "x:pos.x,y:pos.y" *)
> END;
>
> VAR pos : Position;
>
> BEGIN
>    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.
>
>
> Denis
>
> (*) Like in the example Trees module at §11 of the Oberon-2 language report.
> ________________________________
>
> vit esse estrany ☣
>
> spir.wikidot.com
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
>



-- 
-- 
Aubrey McIntosh, Ph.D.
1502 Devon Circle
Austin TX 78723-1814
http://home.grandecom.net/~amcintosh/aubrey/Search/


More information about the Oberon mailing list