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
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@lists.inf.ethz.ch [mailto:oberon-bounces@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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
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@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@lists.inf.ethz.ch [mailto:oberon-bounces@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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@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/
On Tue, 22 Jun 2010 14:24:23 +0200 "Stauber Sven Philipp" <sven.stauber@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...
Thank you, I'll follow the pointers. Actually I knew about the forums, but the one ypu mention does not seem very "active": <<Oberon & Active Oberon Programming Languages 1 Posts 1 Topics>>. Also, mailing list are far more practicle for me. The core of my interest, as of now, is the *language* Oberon as defined in the Oberon-2 report. I use either 002c or obc to compile for the moment. What is A2, actually? The first sentence of the quickstart guide reads "This is a brief introduction to the programming language Active Oberon and the operating system A2." Implementations including the system or a simulation of it on top of another cannot fit my needs. I may switch to ActiveOberon, again only the language, in a far future, if ever I need to address parallel processing issues, but this is completely outside my field of interests today. What I'm looking for is a convenient static and compiled language for a project of mine (actually, a language, too ;-) and to build various tools, mainly for the said project. Oberon-2 seems to be close to perfect.
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.
Right. But the report only seems to use "string" to denote the result of evaluating literal notations like 'abc'. There is no mention of a string type (unlike CHAR). So, I guess there may well be various string representations (and/or types for them) in a given implementation, but they belong to the implementation. Or do I miss a basic point? If not, the point is then: how are Oberon programmers supposed to deal with strings. ARRAY OF CHAR is an obvious answer but does not hold in practice, since it cannot be the type of a VAR or of a return value. On the other hand, bounded ARRAYs size OF CHAR are not proper types for strings, since very few string variables and return values have a predefined size (indeed, they are the result of input or computation). In flexible languages, and in most Pascal variants, there is a type corresponding to the notion of a-piece-of-text and to literals denoting instances of it. My aim is to find the corresponding feature in Oberon-2, or a way to construct such a handy representation myself. In the meanwhile, I'll have a look at the source of A2's String type if it's written in Oberon itself & I can find it.
... 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.
The report explicitely explains that assigning a string (literal) to a var of type ARRAY OF CHAR (which apparently is the only type a var can have to be assigned a string) automagically adds 0X after the string's characters. (The relevant lines of the report are quoted in my original post). This is what I meant above.
[...]
________________________________ vit esse estrany ☣ spir.wikidot.com
Hi,
Right. But the report only seems to use "string" to denote the result of evaluating literal notations like 'abc'. There is no mention of a string type (unlike CHAR). So, I guess there may well be various string representations (and/or types for them) in a given implementation, but they belong to the implementation. Or do I miss a basic point?
No, you're right. For those Oberon implementations (e.g. Native Oberon, A2, ...) I've seen, string representation and manipulation is mainly part of the Oberon "system", not the Oberon language. The only things the Oberon language provides: - string literals - built-in COPY function - Operators: = # < <= > >= also work on 0X-terminated "strings" More advanced string manipulation features as appending a string to another, for example, are implemented as library (as Strings.Mod in Native Oberon/A2). Even more advanced features as text representation are again part of the implementation. Best, Sven -----Ursprüngliche Nachricht----- Von: oberon-bounces@lists.inf.ethz.ch [mailto:oberon-bounces@lists.inf.ethz.ch] Im Auftrag von spir Gesendet: Dienstag, 22. Juni 2010 15:46 An: oberon Betreff: Re: [Oberon] string manipulation On Tue, 22 Jun 2010 14:24:23 +0200 "Stauber Sven Philipp" <sven.stauber@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...
Thank you, I'll follow the pointers. Actually I knew about the forums, but the one ypu mention does not seem very "active": <<Oberon & Active Oberon Programming Languages 1 Posts 1 Topics>>. Also, mailing list are far more practicle for me. The core of my interest, as of now, is the *language* Oberon as defined in the Oberon-2 report. I use either 002c or obc to compile for the moment. What is A2, actually? The first sentence of the quickstart guide reads "This is a brief introduction to the programming language Active Oberon and the operating system A2." Implementations including the system or a simulation of it on top of another cannot fit my needs. I may switch to ActiveOberon, again only the language, in a far future, if ever I need to address parallel processing issues, but this is completely outside my field of interests today. What I'm looking for is a convenient static and compiled language for a project of mine (actually, a language, too ;-) and to build various tools, mainly for the said project. Oberon-2 seems to be close to perfect.
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.
Right. But the report only seems to use "string" to denote the result of evaluating literal notations like 'abc'. There is no mention of a string type (unlike CHAR). So, I guess there may well be various string representations (and/or types for them) in a given implementation, but they belong to the implementation. Or do I miss a basic point? If not, the point is then: how are Oberon programmers supposed to deal with strings. ARRAY OF CHAR is an obvious answer but does not hold in practice, since it cannot be the type of a VAR or of a return value. On the other hand, bounded ARRAYs size OF CHAR are not proper types for strings, since very few string variables and return values have a predefined size (indeed, they are the result of input or computation). In flexible languages, and in most Pascal variants, there is a type corresponding to the notion of a-piece-of-text and to literals denoting instances of it. My aim is to find the corresponding feature in Oberon-2, or a way to construct such a handy representation myself. In the meanwhile, I'll have a look at the source of A2's String type if it's written in Oberon itself & I can find it.
... 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.
The report explicitely explains that assigning a string (literal) to a var of type ARRAY OF CHAR (which apparently is the only type a var can have to be assigned a string) automagically adds 0X after the string's characters. (The relevant lines of the report are quoted in my original post). This is what I meant above.
[...]
________________________________ vit esse estrany ☣ spir.wikidot.com -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
It is not possible to de-reference a pointer returned by a function in an expression. So the following code is as close as I can get, with a pointer assignment, and the pointer then dereferenced. MODULE aTrial; IMPORT Strings, Out; TYPE Position = RECORD x : INTEGER; y : INTEGER; END; String = ARRAY OF CHAR; StringPtr = POINTER TO String; VAR pos : Position; PROCEDURE (VAR pos:Position) text(): StringPtr ; VAR string : StringPtr; BEGIN NEW( string, 24); (*integer to string conversion here.*) COPY ( "(42, 96)", string^); RETURN string END text; PROCEDURE Do*; VAR string : StringPtr; BEGIN Out.String("aTrial.Do "); NEW( string, 32 ); string := pos.text(); Out.String( string^); 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 10:19 AM, Stauber Sven Philipp <sven.stauber@inf.ethz.ch> wrote:
Hi,
Right. But the report only seems to use "string" to denote the result of evaluating literal notations like 'abc'. There is no mention of a string type (unlike CHAR). So, I guess there may well be various string representations (and/or types for them) in a given implementation, but they belong to the implementation. Or do I miss a basic point?
No, you're right. For those Oberon implementations (e.g. Native Oberon, A2, ...) I've seen, string representation and manipulation is mainly part of the Oberon "system", not the Oberon language.
The only things the Oberon language provides:
- string literals - built-in COPY function - Operators: = # < <= > >= also work on 0X-terminated "strings"
More advanced string manipulation features as appending a string to another, for example, are implemented as library (as Strings.Mod in Native Oberon/A2). Even more advanced features as text representation are again part of the implementation.
Best, Sven
-----Ursprüngliche Nachricht----- Von: oberon-bounces@lists.inf.ethz.ch [mailto:oberon-bounces@lists.inf.ethz.ch] Im Auftrag von spir Gesendet: Dienstag, 22. Juni 2010 15:46 An: oberon Betreff: Re: [Oberon] string manipulation
On Tue, 22 Jun 2010 14:24:23 +0200 "Stauber Sven Philipp" <sven.stauber@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...
Thank you, I'll follow the pointers. Actually I knew about the forums, but the one ypu mention does not seem very "active": <<Oberon & Active Oberon Programming Languages 1 Posts 1 Topics>>. Also, mailing list are far more practicle for me. The core of my interest, as of now, is the *language* Oberon as defined in the Oberon-2 report. I use either 002c or obc to compile for the moment. What is A2, actually? The first sentence of the quickstart guide reads "This is a brief introduction to the programming language Active Oberon and the operating system A2." Implementations including the system or a simulation of it on top of another cannot fit my needs. I may switch to ActiveOberon, again only the language, in a far future, if ever I need to address parallel processing issues, but this is completely outside my field of interests today. What I'm looking for is a convenient static and compiled language for a project of mine (actually, a language, too ;-) and to build various tools, mainly for the said project. Oberon-2 seems to be close to perfect.
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.
Right. But the report only seems to use "string" to denote the result of evaluating literal notations like 'abc'. There is no mention of a string type (unlike CHAR). So, I guess there may well be various string representations (and/or types for them) in a given implementation, but they belong to the implementation. Or do I miss a basic point? If not, the point is then: how are Oberon programmers supposed to deal with strings. ARRAY OF CHAR is an obvious answer but does not hold in practice, since it cannot be the type of a VAR or of a return value. On the other hand, bounded ARRAYs size OF CHAR are not proper types for strings, since very few string variables and return values have a predefined size (indeed, they are the result of input or computation). In flexible languages, and in most Pascal variants, there is a type corresponding to the notion of a-piece-of-text and to literals denoting instances of it. My aim is to find the corresponding feature in Oberon-2, or a way to construct such a handy representation myself. In the meanwhile, I'll have a look at the source of A2's String type if it's written in Oberon itself & I can find it.
... 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.
The report explicitely explains that assigning a string (literal) to a var of type ARRAY OF CHAR (which apparently is the only type a var can have to be assigned a string) automagically adds 0X after the string's characters. (The relevant lines of the report are quoted in my original post). This is what I meant above.
[...]
________________________________
vit esse estrany ☣
spir.wikidot.com -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@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/
On Tue, 22 Jun 2010 17:19:11 +0200 "Stauber Sven Philipp" <sven.stauber@inf.ethz.ch> wrote:
For those Oberon implementations (e.g. Native Oberon, A2, ...) I've seen, string representation and manipulation is mainly part of the Oberon "system", not the Oberon language.
The only things the Oberon language provides:
- string literals - built-in COPY function - Operators: = # < <= > >= also work on 0X-terminated "strings"
More advanced string manipulation features as appending a string to another, for example, are implemented as library (as Strings.Mod in Native Oberon/A2). Even more advanced features as text representation are again part of the implementation.
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: Out.String(aText); I thus need an additional method to return the char sequence itself: Out.String(aText.chars()); 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? Denis ________________________________ vit esse estrany ☣ spir.wikidot.com
Denis, 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 TYPE 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; BEGIN Out.String(text.string) END Out; and also a way to set the string PROCEDURE (VAR text: Text) Set (IN x: ARRAY OF CHAR), NEW; BEGIN NEW(text.string, 1+LEN(x$)); text.string^:=x$; END Set; and then do PROCEDURE Do*; VAR text: Text; BEGIN text.Set("Hello, World!"); text.Out; Out.Ln END Do; 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. -Doug Danforth spir wrote:
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: Out.String(aText); I thus need an additional method to return the char sequence itself: Out.String(aText.chars()); 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?
Denis
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: Out.String(aText); I thus need an additional method to return the char sequence itself: Out.String(aText.chars()); 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.
The closest that I have seen to what you are asking for is the superset / extension of Oberon-2 that started life as Oberon/L and is now known as Component Pascal. There is a section "String Support" in the document "What is New in Component Pascal" that also details the other extensions and differences: www.oberon.ch/pdf/CP-New.pdf You can download the full version of the software including all source code from: http://www.oberon.ch/blackbox.html There is also a version callled Gardens Point Component Pascal that runs on the JVM and .NET. The .NET version has ARRAY OF CHAR / System.String conversions so that you can use .NET's built-in System.String data type and its many thousands (ok - maybe I exaggerate a little!) of related functions. http://plas.fit.qut.edu.au/gpcp/
* Why no dynamic array in Oberon?
Wirth's most recent Oberon-07 ARM compiler does have one-dimensional dynamic arrays but this is implemented as an extension - it is not defined in the language: http://www.inf.ethz.ch/personal/wirth/Articles/Oberon.html My understanding is that he intends the Language Report to define a language that is implementable as widely as possible WITHOUT ANY SUBSETS. Extensions are OK. As long as you stick to the features defined in the language report your code should be as portable as is practically possible (far more so than is possible with C, say). Our Oberon-07 development system (Astrobe) supports the development of embedded software for ARM microcontrollers which can have as little as 16K of ROM for program code and 2K of RAM for data so a language that includes features that mandate a garbage collector for reliable operation is obviously out of the question ;-) http://www.astrobe.com In the version of the Oberon-07 ARM compiler used in Astrobe we currently only support local dynamic arrays. The syntax is: ArrayType = "ARRAY OF" type. e.g. PROCEDURE P(); VAR counts: ARRAY OF INTEGER; weights: ARRAY OF REAL; alarms: ARRAY OF Event; ... ... The length of a local dynamic array is established by a call to NEW with a second parameter indicating the desired number of array elements. For example: NEW(counts, 100) The great advantage of local dynamic arrays is that they can be safely allocated on the stack. Thus no garbage collector or special treatment is required to free their memory when the procedure terminates. This allows the most efficient use of memory without the associated problems of memory leaks and fragmentation. Regards, Chris Burrows CFB Software http://www.cfbsoftware.com
On Wed, 23 Jun 2010 10:07:13 +0930 "Chris Burrows" <chris@cfbsoftware.com> wrote: Thank you very much for this extensive reply.
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: Out.String(aText); I thus need an additional method to return the char sequence itself: Out.String(aText.chars()); 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.
The closest that I have seen to what you are asking for is the superset / extension of Oberon-2 that started life as Oberon/L and is now known as Component Pascal. There is a section "String Support" in the document "What is New in Component Pascal" that also details the other extensions and differences:
www.oberon.ch/pdf/CP-New.pdf
You can download the full version of the software including all source code from:
http://www.oberon.ch/blackbox.html
There is also a version callled Gardens Point Component Pascal that runs on the JVM and .NET. The .NET version has ARRAY OF CHAR / System.String conversions so that you can use .NET's built-in System.String data type and its many thousands (ok - maybe I exaggerate a little!) of related functions.
Right, I will follow the pointers. A language that defines a literal notation, "string", without any corresponding data type, seems to me rather strange. This is the only case in Oberon, I guess (even chars have a type). The same applied to Pascal (even extended IIRC) but concrete implementations for real-world (all I know of, at least) _did_ introduce a string type. The issue is, as I see it, and if I'm right: one can construct such a handy abstraction in Pascal or Oberon but it is then close to useless since all the language's constructs and builtin tools simply do not know it (assignment, I/O, conversions...). So that it's not enough to build the abstraction, a dedicated compiler is needed that will, for instance, construct a String when reading a string literal, instead of an internal representation mapping to no user-available type. This is to oppose to a string toolbox simply extending Oberon-defined procs & funcs and operating on open arrays of char as formal parameters. So, to sum up: a kind of background, transparent, magic is needed to make a String type useful (implemented in the compiler itself, not built on top of the language as is). But I would be pleased to know I'm wrong on this so as to be able to build one, for and in "standard" Oberon-2.
* Why no dynamic array in Oberon?
Wirth's most recent Oberon-07 ARM compiler does have one-dimensional dynamic arrays but this is implemented as an extension - it is not defined in the language:
Great. So, I may be wrong. Hope I can find the source and watch how it is implemented.
My understanding is that he intends the Language Report to define a language that is implementable as widely as possible WITHOUT ANY SUBSETS.
What do you mean?
Extensions are OK. As long as you stick to the features defined in the language report your code should be as portable as is practically possible (far more so than is possible with C, say).
Our Oberon-07 development system (Astrobe) supports the development of embedded software for ARM microcontrollers which can have as little as 16K of ROM for program code and 2K of RAM for data so a language that includes features that mandate a garbage collector for reliable operation is obviously out of the question ;-)
This would require forbidding pointers to records and arrays, no? Otherwise deallocation is left to the user and thus "reliable operation" cannot be ensured...
In the version of the Oberon-07 ARM compiler used in Astrobe we currently only support local dynamic arrays. The syntax is:
ArrayType = "ARRAY OF" type.
e.g. PROCEDURE P(); VAR counts: ARRAY OF INTEGER; weights: ARRAY OF REAL; alarms: ARRAY OF Event; ... ...
The length of a local dynamic array is established by a call to NEW with a second parameter indicating the desired number of array elements. For example:
NEW(counts, 100)
Close to perfect :-) I guess since it is defined as local-scope only feature, one cannot return an open array as func result (unless it is assigned to an open array VAR of a higher-level procedure?). But the ability to define one VAR as open array is already a huge step in terms of programmer-friendliness. I'm surprised this is not a standard feature of Wirth language, since as I see it this does not reduce language safety: the size must be bound for concrete use of the VAR; checking (eg array bounds) is simply done at runtime instead of compile-time. This fact makes checking slower and delays error recognition, but does not really makes the language less safe; and anyway, this is programmer choice.
The great advantage of local dynamic arrays is that they can be safely allocated on the stack. Thus no garbage collector or special treatment is required to free their memory when the procedure terminates. This allows the most efficient use of memory without the associated problems of memory leaks and fragmentation.
Seems to be a sensible choice, esp. for embedded software. (For design choices toward light, practicle and efficient software in the field of embedded programming, but in a highly flexible dynamic language, Lua is a good source of inspiration, I guess.)
Regards, Chris Burrows
Denis ________________________________ vit esse estrany ☣ spir.wikidot.com
participants (5)
-
Aubrey.McIntosh@Alumni.UTexas.Net -
Chris Burrows -
Douglas G. Danforth -
spir -
Stauber Sven Philipp