[Oberon] Oberon Digest, Vol 237, Issue 2

Hans Klaver hklaver at dds.nl
Sat Feb 10 17:21:40 CET 2024


Hi Daniel,

You wrote: 

> Have no idea how to In.Char(ch);
> 
> About 1000 lines of code seem to work fine (a server to poll remote
> devices via tcp) but now i would like to get a user keyboard input
> but i get stuck:
> 
> PROCEDURE Test2;
> VAR b: BOOLEAN; ch: CHAR;
> BEGIN(*PROCEDURE*)
>   Out.String("input: ");
>   b:= In.Char(ch);
>   Out.Char(ch);
> END(*PROCEDURE*) Test2;
> 
> compiles fine but doesn't even stop for an input? any idea/hint?

Which Oberon compiler / operating system / development environment do you use?

Unfortunately different implementations of Module In may vary somewhat in their use:

- Sometimes In.Open has to be called first to initialize the input stream.
- It is unusual that In.Char(ch) returns a boolean; all implementations of
  module In that I know use procedures with VAR parameters for input and 
  do not return any value like your implementation appears to do.
- Most implementations of In use a boolean variable In.Done that is 
  declared outside any of the procedures of In (so it is a global variable
  of module In), which can be tested to see if all the input up to the test
  was successful.

For example using the OBNC command line compiler for Windows/Linux/macOS 
the following should work:
  
  MODULE TestIn;
    IMPORT In, Out;

    PROCEDURE Test2;
      VAR ch: CHAR;
    BEGIN
      Out.String("Input a character and then press <enter>: ");
      In.Open;  (* in OBNC this has no effect, but you could try it *)
      In.Char(ch);
      IF In.Done THEN
        Out.Char(ch)
      ELSE                             (* not useful for this character input, *)
        Out.String("Parameter error")  (* but is useful for other input types  *)
      END;
      Out.Ln
    END Test2;

  BEGIN
    Test2
  END TestIn.


Another example is the use of In in the Oberon System, which has no command line.
There its use is more like described in the book by Reiser & Wirth "Programming 
in Oberon". After compilation the following module prints itself to the System.Log
text, even before the text is saved to a file:

  MODULE Print;  (* Hans Klaver, 09-May-1999 *)
  (** To execute mark this viewer with * and middle-click Print.Me **)
    IMPORT In, Out;

    PROCEDURE Me*;
      VAR ch: CHAR;
    BEGIN
      In.Open;  (* is obligatory in the Oberon System! *)
      In.Char(ch);
      WHILE In.Done DO
        Out.Char(ch);
        In.Char(ch)
      END
    END Me;

  END Print.Me*


In Wirth's latest version of the Oberon System: 
  https://people.inf.ethz.ch/wirth/ProjectOberon/index.html
modules In.Mod and Out.Mod are lacking. In that case you
could use my In.Mod and Out.Mod: https://github.com/hansklav/Oberon-07

Some other versions of the Oberon System include In.Mod and Out.Mod,
e.g. https://github.com/andreaspirklbauer/Oberon-extended


Regards,

Hans Klaver



More information about the Oberon mailing list